Ruby 解压字符串 [英] Ruby Unzip String
本文介绍了Ruby 解压字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在 Ruby 中使用压缩(常规 Zip)字符串.显然我无法使用 Ruby-Zip 或 Zip-Ruby.
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 从 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
这篇关于Ruby 解压字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文