Class: WickedPdf::Tempfile
- Inherits:
-
Tempfile
- Object
- Tempfile
- WickedPdf::Tempfile
- Defined in:
- lib/wicked_pdf/tempfile.rb
Instance Method Summary collapse
-
#initialize(filename, temp_dir = nil) ⇒ Tempfile
constructor
A new instance of Tempfile.
- #read_in_chunks ⇒ Object
- #write_in_chunks(input_string) ⇒ Object
Constructor Details
#initialize(filename, temp_dir = nil) ⇒ Tempfile
Returns a new instance of Tempfile.
8 9 10 11 12 13 |
# File 'lib/wicked_pdf/tempfile.rb', line 8 def initialize(filename, temp_dir = nil) temp_dir ||= Dir.tmpdir extension = File.extname(filename) basename = File.basename(filename, extension) super([basename, extension], temp_dir) end |
Instance Method Details
#read_in_chunks ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/wicked_pdf/tempfile.rb', line 25 def read_in_chunks rewind binmode chunks = [] chunks << read(chunk_size) until eof? chunks.join rescue Errno::EINVAL => e raise e, end |
#write_in_chunks(input_string) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/wicked_pdf/tempfile.rb', line 15 def write_in_chunks(input_string) binmode string_io = StringIO.new(input_string) write(string_io.read(chunk_size)) until string_io.eof? close self rescue Errno::EINVAL => e raise e, end |