Method: EPUBMeta::Models::Cover#tempfile
- Defined in:
- lib/epubmeta/models/cover.rb
#tempfile(&block) ⇒ File
Cover file Tempfile is used to enable access to cover file If block is passed, the tempfile is passed to it and closed after the block is executed
cover.file do { |f| puts f.size }
Otherwise user is responsible to unlink and close tempfile
file = book.cover.file
file.size
file.close!
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/epubmeta/models/cover.rb', line 49 def tempfile(&block) tempfile = Tempfile.new('epubmeta') tempfile.binmode cover_file = @parser.zip_file.read(zip_file_path) tempfile.write(cover_file) if block_given? yield tempfile tempfile.close! else # user is responsible for closing file tempfile end end |