Class: TheTvDB::Zip
- Inherits:
-
Object
- Object
- TheTvDB::Zip
- Defined in:
- lib/the_tv_db/utils/zip.rb
Instance Attribute Summary collapse
-
#tmp ⇒ Object
Returns the value of attribute tmp.
Instance Method Summary collapse
-
#deflate(string) ⇒ Object
Compresses the given string.
-
#inflate(string) ⇒ Object
Decompresses string.
-
#initialize ⇒ Zip
constructor
A new instance of Zip.
Constructor Details
#initialize ⇒ Zip
Returns a new instance of Zip.
8 9 10 |
# File 'lib/the_tv_db/utils/zip.rb', line 8 def initialize @tmp = Tempfile.new('thetvdb.com') end |
Instance Attribute Details
#tmp ⇒ Object
Returns the value of attribute tmp.
6 7 8 |
# File 'lib/the_tv_db/utils/zip.rb', line 6 def tmp @tmp end |
Instance Method Details
#deflate(string) ⇒ Object
Compresses the given string.
26 27 28 29 |
# File 'lib/the_tv_db/utils/zip.rb', line 26 def deflate(string) tmp.write(string.force_encoding("utf-8")) ::Zip::ZipFile.new(tmp) end |
#inflate(string) ⇒ Object
Decompresses string.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/the_tv_db/utils/zip.rb', line 13 def inflate(string) entries = {} deflated = deflate(string) deflated.each do |entry| entries[entry.name] = entry.get_input_stream.read end entries ensure tmp.close tmp.unlink end |