Skip to content

right way to add an entry from a stream or memory, not a file? with mode STORED? #400

Closed
@jrochkind

Description

@jrochkind

I'm getting a bit confused about the rubyzip api.

I am creating a zip file, and want to add an entry to it where:

  1. I do not have a local File for the contents I want to add. I have the data in memory (or in an IO stream object that is not a File)
  2. I want to add the entry as STORED, mode not DEFLATE.

For the first criteria, not having a local file, I think this would work:

Zip::OutputStream.open('exampleout.zip') do |zos|
  zos.put_next_entry(desired_filename)
  zos.puts some_binary_content
end

For the second criteria, STORED rather than DEFLATE, I figured out with difficulty this:

 entry = ::Zip::Entry.new(zipfile.name, desired_filename, nil, nil, nil, nil, ::Zip::Entry::STORED)
 zipfile.add(entry, File.open("something"))

But these are entirely different APIs. For the OutputStream API in the first example... there doens't seem to be any way to specify STORED rather than DEFLATE?

For the Zip::Entry/add API in the second example... there doesn't seem to be any way to pass it something that isn't a real file object. If I pass it a string to zipfile.add(entry, "foo bar"), I get No such file or directory @ rb_file_s_lstat - foo bar.

Is there any API that does both things? Looking at the source for the #add method, it's described as a "convenience method", so maybe I can do just what it's doing myself in more steps -- but it's implementation accesses the @entry_set iVar, so I can't do just what it does in my own caller code....

Is there any API that has all the features I need?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions