'rubyzip 2.3.2 read fails on macOS 10.15.7, ruby 3.1.1p18

This fails:

    zip = Zip::File.open_buffer(@archive_io, encoding:"UTF-8")
    contents = zip.read(filename)

with this error:

    Errno::ENOENT: No such file or directory - content.xml

This succeeds:

    zip = Zip::File.open_buffer(@archive_io, encoding:"UTF-8")
    while zip.size == 0
        zip = Zip::File.open_buffer(@archive_io, encoding:"UTF-8")
    end
    contents = zip.read(filename)

Why?

Note that @archive_io is a StringIO instance. 'filename' is an entry in the zip file known to exist of 6253 uncompressed bytes. When using Pry as a debugger, I can simply retype/rerun the open_buffer method and suddenly the zip read works. This lead to me adding the loop to re-attempt the open_buffer - a kludge of a solution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source