Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby - the simplest way to read a text file inside a zip file

Tags:

ruby

zip

What is the simplest way to read a text file inside a zip file in Ruby? Something similar to PHP's file_get_contents("zip://archive.zip#article.txt")

like image 538
powerboy Avatar asked Jul 12 '12 06:07

powerboy


2 Answers

require 'zip/zip'

Zip::ZipFile.new("archive.zip").read("article.txt")
like image 145
Alex Avatar answered Nov 01 '22 20:11

Alex


Try it

require 'zip/zip'

Zip::ZipFile.open("my.zip", Zip::ZipFile::CREATE) {|zipfile|  puts zipfile.read("first.txt")}
like image 2
Shamith c Avatar answered Nov 01 '22 19:11

Shamith c