-
Notifications
You must be signed in to change notification settings - Fork 314
Undefined method 'path' #119
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
Comments
@mperham Sorry I'm on vacation now. Can you check my fix and tell me what all works fine. Thank you for the issue! |
Now I get this:
Could you write a test which reproduces my problem? That'll get us to a fix quicker. Here's the actual code I'm using, modified to work with the rubyzip project so you can use it for a test: fname = "./README.md"
zname = "README.zip"
Zip::File.open(zname, Zip::File::CREATE) do |zipfile|
zipfile.get_output_stream(File.basename(fname)) { |f| f.puts File.read(fname) }
end
data = nil
Zip::File.open_buffer(File.read(zname)) do |zipfile|
zipfile.each do |entry|
next unless entry.name =~ /README.md/
data = zipfile.read(entry)
end
end
assert data
assert data =~ /Simonov/ I'm using a buffer, not reading from a file, because the zip data is actually coming from our database. |
@mperham fixed. Can you test it on your application? |
I don't have the bandwidth anymore but if the test passes I'll trust that things are better now. |
@mperham ok. Thank you for your help. |
mperham , did you manage to read the zipfile from the database? I am not able todo it properly. The only solution I found is this http://stackoverflow.com/questions/13730720/how-to-iterate-through-an-in-memory-zip-file-in-ruby where I have to change the StringIO class. In case you got it to work, can you please tell me how? Your code above from the test does not work, it fails with: Zip::ZipFile.open_buffer expects an argument of class String or IO. Found: String, which makes no sense to me. |
Sorry, for some reason I still had version 1.0.0 installed |
@timmi-on-rails so you updated to fixed version? or not? |
I am using axlsx, that was the reason for the old version of rubyzip used... (now I use the zip-zip gem for compatibility, but it doesn't work with axlsx, but nvm, I guess I can somehow use the old and new gem at the same time?!) Having version 1.1.2 now Zip::File.open(fname) do |zipfile| end what doesnt work is Zip::File.open_buffer(File.read(fname)) ...with the same file, I get: Zip end of central directory signature not found If I actually put some in memory data from my database Zip::File.open_buffer(@project.probe_data) ... I get: undefined method `bytesize' for nil:NilClass, somewhere in the entry.rb ...(read_local_entry) Then I tried using InputStream.open_buffer , but I get different problems there... :-( I just want to read a zipfile that I have as binary string stored in a variable. |
In the old API this works for me: Zip::InputStream.open_buffer(StringIO.new(@project.probe_data)) do |io| while entry = io.get_next_entry logger.debug entry.name end end with this patch: class StringIO def path end end However in the new API this doesnt work. |
In new version your code must working too! Zip::InputStream.open_buffer(StringIO.new(@project.probe_data)) do |io|
while entry = io.get_next_entry
logger.debug entry.name
end
end There is no need to have path in StringIO |
Well that code returns zero entries in the new version and a deprecated warning. I just found out that it works in the new version, if I use Zip::InputStream.open instead of Zip::InputStream.open_buffer The the undefined method "bytesize" seems to be a whole other issue that only happens for "xlsx" files. Actually if I create a zip with not just plain files, but subfolders, the issue happens. But I am not sure about the exact circumstances. Edit: |
File: entry.rb in method: read_local_entry, the line static_sized_fields_buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH) evaluates as Nil Class, therefore in line 224 unless static_sized_fields_buf.bytesize == ::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH complains the missing bytesize method I don't have a fix yet, because I dont know the whole thing very well :( |
I am running into the same problem with this zip file, containing only two files, This: Zip::File.open_buffer(File.open('thing.zip')) And this: Zip::File.open_buffer(File.read('thing.zip')) Both result in this:
I noticed in ::File.open(name, 'rb') do |f| I tried this: Zip::File.open_buffer(File.open('thing.zip', 'rb')) And got a different error:
It seems the interface of |
Please check if setting the encoding in your StringIO object solves the issue, it did for me on a related problem I had: |
I'm just doing this where
det.content
is a String of binary data.The text was updated successfully, but these errors were encountered: