如何解压缩文件或读取zip文件的内容以选择要提取的内容?如何使用zlib充气和读取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
啊,我没想到它是如此容易地运行在Ruby中的bash命令......我知道,拉链, gzip是不同的,但我很惊讶Ruby没有内置zip文件。 gzip可能会更好,但zip是如此普遍!感谢您的高举。 – beoliver