I have to work with a zipped (regular Zip) string in Ruby. Apparently I can't save a temporary file with Ruby-Zip or Zip-Ruby.
Is there any practicable way to unzip this string?
rubyzip supports StringIO since version 1.1.0
require "zip"
# zip is the string with the zipped contents
Zip::InputStream.open(StringIO.new(zip)) do |io|
while (entry = io.get_next_entry)
puts "#{entry.name}: '#{io.read}'"
end
end
See Zip/Ruby Zip::Archive.open_buffer(...)
:
require 'zipruby'
Zip::Archive.open_buffer(str) do |archive|
archive.each do |entry|
entry.name
entry.read
end
end
As the Ruby-Zip seems to lack support of reading/writing to IO objects, you can fake File. What you can do is the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With