Ruby is the easiest way to read a text file inside a zip file

What is the easiest way to read a text file inside a zip file in Ruby? Something similar to PHPfile_get_contents("zip://archive.zip#article.txt")

+5
source share
3 answers
require 'zip/zip'

Zip::ZipFile.new("archive.zip").read("article.txt")
+11
source

Try

require 'zip/zip'

Zip::ZipFile.open("my.zip", Zip::ZipFile::CREATE) {|zipfile|  puts zipfile.read("first.txt")}
+2
source

I think this should work:

require 'zipruby'

Zip::Archive.open('archive.zip') do |ar|
   ar.fopen('article.txt') do |f|
      content = f.read
      # do sth
   end
end
+1
source

All Articles