【发布时间】:2011-05-03 14:59:35
【问题描述】:
【问题讨论】:
【问题讨论】:
rubyzipsupports 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
【讨论】:
见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
【讨论】:
由于 Ruby-Zip 似乎缺乏对 IO 对象的读/写支持,您可以伪造 File. 您可以执行以下操作:
【讨论】:
正如@Roman 提到的,rubyzip 目前缺乏对 IO 对象的读写(包括StringIO.new(s))。尝试改用zipruby,如下所示:
gem install zipruby
require 'zipruby'
# Given a string in zip format, return a hash where
# each key is an zip archive entry name and each
# value is the un-zipped contents of the entry
def unzip(zipfile)
{}.tap do |h|
Zip::Archive.open_buffer(zipfile) do |archive|
archive.each {|entry| h[entry.name] = entry.read }
end
end
end
【讨论】:
zlib 库。与 StringIO 一起工作正常。
【讨论】: