8000 Problem with open_buffer · Issue #177 · rubyzip/rubyzip · GitHub
[go: up one dir, main page]

Skip to content

Problem with open_buffer #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sandrods opened this issue Aug 1, 2014 · 6 comments
Closed

Problem with open_buffer #177

sandrods opened this issue Aug 1, 2014 · 6 comments

Comments

@sandrods
Copy link
sandrods commented Aug 1, 2014

I'm getting undefined method bytesize' for nil:NilClass`using open_buffer.

this code works:

data = string_with_zip_file
::File.open('my_file.zip', "wb") {|f| f.write(data) }
Zip::File.open('my_file.zip')

but if I try to use open_buffer

data = string_with_zip_file
Zip::File.open_buffer(data)

I get this error:

NoMethodError: NoMethodError: undefined method `bytesize' for nil:NilClass
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/entry.rb:224:in `read_local_entry'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/entry.rb:194:in `read_local_entry'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/output_stream.rb:114:in `block in copy_raw_entry'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/entry.rb:557:in `get_raw_input_stream'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/output_stream.rb:112:in `copy_raw_entry'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/entry.rb:545:in `write_to_zip_output_stream'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/file.rb:318:in `block (2 levels) in write_buffer'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/entry_set.rb:42:in `call'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/entry_set.rb:42:in `block in each'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/entry_set.rb:41:in `each'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/entry_set.rb:41:in `each'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/file.rb:318:in `block in write_buffer'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/output_stream.rb:60:in `write_buffer'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/file.rb:317:in `write_buffer'
  .rbenv/versions/1.9.3-p327/.../rubyzip-1.1.6/lib/zip/file.rb:128:in `open_buffer'

Am I doing something wrong?

@drock
Copy link
drock commented Nov 5, 2014

I am getting the same thing.

I switched to using Zip::InputStream instead. Example:

Zip::InputStream.open(StringIO.new(data)) do |zis|
      while entry = zis.get_next_entry
          puts entry.name
      end
end

@mpwdawson
Copy link

I'm running into this same error: NoMethodError: undefined method `bytesize' for nil:NilClass, but it looks like OS X's .DS_Store is the culprit. Zip::File.open works fine, but Zip::File.open_buffer raises the error. I can work around this, but hopefully this can be fixed?

My code:

contents = []
Zip::File.open_buffer(File.open("zip_test.zip", "rb").read) do |zip_file|
  zip_file.each do |entry|
    contents << entry.get_input_stream.read
  end
end

Sample attachment you can use: https://s3.amazonaws.com/github-rubyzip/zip_test.zip

Thanks.

@kylekyle
Copy link

It looks like this is not going to be fixed. Can a project maintainer just mark it as such and make the method private so people aren't led to believe they can open a buffer directly?

@aalvarado
Copy link

I was getting this error while trying to use the Roo gem.

It looks like it was an encoding issue. We had something like this:

Roo::Excelx.new(StringIO.new(xlsx_report.file_data))

and getting

NoMethodError:
       undefined method `bytesize' for nil:NilClass

loading it like this:

Roo::Excelx.new(StringIO.new(xlsx_report.file_data).set_encoding('ASCII-8BIT'))

solves the issue.

@bpina
Copy link
bpina commented May 4, 2017

I received this error as well, but it only occurred when I ran the code on OS X. There was no problem opening the buffer on Linux (Gentoo or Ubuntu).

Here's some example code that could reproduce the problem on OS X:

Zip::File.open_buffer(File.read('/path/to/my_zip.zip'))

I was able to resolve the issue on OS X by changing my code to:

Zip::File.open_buffer(File.binread('/path/to/my_zip.zip'))

@hainesr
Copy link
Member
hainesr commented Jun 18, 2021

Fixed, as far as I can tell.

@hainesr hainesr closed this as completed Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
0