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.


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

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


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

def read_in_chunks
  rewind
  binmode
  output_string = ''
  output_string << read(chunk_size) until eof?
  output_string
rescue Errno::EINVAL => e
  raise e, file_too_large_message
end

#write_in_chunks(input_string) ⇒ Object


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

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