class WickedPdf::Tempfile

Public Class Methods

new(filename, temp_dir = nil) click to toggle source
Calls superclass method
# 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

Public Instance Methods

read_in_chunks() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

chunk_size() click to toggle source
# File lib/wicked_pdf/tempfile.rb, line 35
def chunk_size
  1024 * 1024
end
file_too_large_message() click to toggle source
# File lib/wicked_pdf/tempfile.rb, line 39
def file_too_large_message
  'The HTML file is too large! Try reducing the size or using the return_file option instead.'
end