Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: reading a temporary zip file

I have a TempFile object that is a zip file, and I wish to read from it as follows:

Zip::ZipFile.open_buffer(tempfile) do |zipfile|
    ...
end

However, when I do this, I get the following error:

Zip::ZipFile.open_buffer expects an argument of class String or IO. Found: Tempfile

I've also tried

Zip::ZipFile.open(tempfile.path) do |zipfile|
    ...
end

But that returns

can't dup NilClass

How can I process a temporary zip file?

like image 743
Kkkev Avatar asked Oct 25 '12 19:10

Kkkev


1 Answers

See the following article http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/ which explains how to use the more basic interface Zip::ZipOutputStream if you work with a Tempfile

like image 126
peter Avatar answered Oct 02 '22 17:10

peter