Requires Rubyzip 1.1.0+
Given a data
of Zip file that is read from an IO, extract that data into a Hash.
def unzip(data)
fin = StringIO.new(data)
entries = {}
::Zip::InputStream.open(fin) do |fzip|
while entry = fzip.get_next_entry
entries[entry.name] = fzip.read
end
end
entries
end
Example:
entries = unzip(open("http://example.com/archive.zip").read)
entries["file.txt"] #=> "Hello World\n" (File Content)