Class: WickedPdf::Tempfile

Inherits:
Tempfile
  • Object
show all
Defined in:
lib/wicked_pdf/tempfile.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, temp_dir = nil) ⇒ Tempfile

Returns a new instance of Tempfile.



6
7
8
9
10
11
# File 'lib/wicked_pdf/tempfile.rb', line 6

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_chunksObject



23
24
25
26
27
28
29
30
31
# File 'lib/wicked_pdf/tempfile.rb', line 23

def read_in_chunks
  rewind
  binmode
  chunks = []
  chunks << read(chunk_size) until eof?
  chunks.join
rescue Errno::EINVAL => e
  raise e, file_too_large_message
end

#write_in_chunks(input_string) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/wicked_pdf/tempfile.rb', line 13

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, file_too_large_message
end