Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid "Zip end of central directory signature not found (Zip::Error)" with rubyzip?

Tags:

ruby

rubyzip

I'm reading a lot of zip file with rubyzip.

However this error message is always showing in only specific file even it is zip file.

/app/vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/lib/zip/central_directory.rb:143:in `get_e_o_c_d': Zip end of central directory signature not found (Zip::Error)

I guess this error occures in rubyzip.

How can I manage this error?

Here is my code.

url = 'http://example.zip'

zipfilename = open(url)

Zip::File.open(zipfilename, :allow_redirections => :all) do |zip_file|

   entry = zip_file.glob("*ixbrl.htm").first

   stream = entry.get_input_stream.read

   puts stream

end

Thank you!

like image 608
T.Akashi Avatar asked Aug 12 '17 11:08

T.Akashi


2 Answers

I faced this error when I try to extract data from a uploaded .xlsx file in my application. On my context, the .xlsx file was corrupted, so my solution was save the content (I usually handle the buffer file after the upload) as a csv file (in my application I dont need to worry about the file extension), fixing the content by force it to encode as utf-8, and extract it's data after it. here is a example of the code, I'm using roo-xls gem to handle .xls files and roo gem to handle .csv and .xlsx files.

like image 199
Matheus Porto Avatar answered Oct 24 '22 11:10

Matheus Porto


I ran into the same error. Also only reproducible on Heroku. The error was fixed after I added an unzip buildpack (second, after Ruby).

https://github.com/davidlibrera/heroku-buildpack-unzip

like image 2
chrisM Avatar answered Oct 24 '22 13:10

chrisM