【发布时间】:2012-01-26 20:36:52
【问题描述】:
如何解压缩文件或读取 zip 文件的内容以选择要提取的内容?
.pencast 是 zip 压缩的,所以我可以在 bash 中使用以下内容:
unzip -j *.pencast "*.aac"
但在 Ruby 中:
require 'zlib'
afile = "/Users/name/Desktop/Somepencast.pencast"
puts afile
def inflate(string)
zstream = Zlib::Inflate.new
buf = zstream.inflate(string)
zstream.finish
zstream.close
buf
end
inflate(afile)
结果:
/Users/name/Desktop/Somepencast.pencast
prog1.rb:11:in `inflate': incorrect header check (Zlib::DataError)
from prog1.rb:11:in `inflate'
from prog1.rb:17
【问题讨论】: