简体   繁体   中英

How can I avoid "Zip end of central directory signature not found (Zip::Error)" with 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!

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.

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

If you're using a docs xlsx file try checking if the access of the sheet link is public.

In my case the file was corrupted too. Just has Matheus Porto shows above!

  *Zip end of central directory signature not found (Zip::Error)*
  ./features/Classes/CSVmanubula.rb:268:in `new'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM