Class: TheTvDB::Zip

Inherits:
Object
  • Object
show all
Defined in:
lib/the_tv_db/utils/zip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeZip

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

#tmpObject

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