在Ruby中读取zip文件中的文本文件的最简单方法是什么?类似于PHP file_get_contents("zip://archive.zip#article.txt")
答案 0 :(得分:11)
require 'zip/zip'
Zip::ZipFile.new("archive.zip").read("article.txt")
答案 1 :(得分:2)
试试吧
require 'zip/zip'
Zip::ZipFile.open("my.zip", Zip::ZipFile::CREATE) {|zipfile| puts zipfile.read("first.txt")}
答案 2 :(得分:1)
我认为应该有效:
require 'zipruby'
Zip::Archive.open('archive.zip') do |ar|
ar.fopen('article.txt') do |f|
content = f.read
# do sth
end
end