Ruby 解压字符串

pex*_*pex 5 ruby zip

我必须在 Ruby 中使用压缩(常规 Zip)字符串。显然我无法使用Ruby-Zip或Zip-Ruby保存临时文件。

有没有可行的方法来解压这个字符串?

Llu*_*uís 6

rubyzip 从 1.1.0 版本开始支持 StringIO

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
Run Code Online (Sandbox Code Playgroud)


Ela*_*lad -1

zlib 库。与 StringIO 配合良好。