Skip to content
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

Add missing Zip::Entry arguments to Zip::File#get_output_stream #100

Closed
mdesantis opened this issue Oct 10, 2013 · 2 comments
Closed

Add missing Zip::Entry arguments to Zip::File#get_output_stream #100

mdesantis opened this issue Oct 10, 2013 · 2 comments

Comments

@mdesantis
Copy link
Contributor

Using Zip::File#get_output_stream with a non-Zip::Entry instance as entry argument you cannot specify the other Zip::Entry arguments, like for example compression method.

This monkey patch allows it:

require 'zip'

module Zip
  class File
    def get_output_stream(entry, permissionInt = nil, comment = nil, extra = nil, compressed_size = nil, crc = nil, compression_method = nil, size = nil, time = nil,  &aProc)
      newEntry =
        if entry.kind_of?(Entry)
          entry
        else
          Entry.new(@name, entry.to_s, comment, extra, compressed_size, crc, compression_method, size, time)
        end

      if newEntry.directory?
        raise ArgumentError,
              "cannot open stream to directory entry - '#{newEntry}'"
      end
      newEntry.unix_perms = permissionInt
      zipStreamableEntry  = StreamableStream.new(newEntry)
      @entry_set << zipStreamableEntry
      zipStreamableEntry.get_output_stream(&aProc)
    end
  end
end

# example
Zip::File.open('test.zip', Zip::File::CREATE) do |archive|
  # enter a non compressed entry 
  archive.get_output_stream("first.txt", nil, nil, nil, nil, nil, Zip::Entry::STORED) { |f| f.puts "Hello from ZipFile" }
end
@simonoff
Copy link
Member

Can you make a pull request with changes and tests?

@mdesantis
Copy link
Contributor Author

Yes, I will

simonoff added a commit that referenced this issue Oct 19, 2013
Add entry arguments to Zip::File#get_output_stream. Fixes #100
githubmo pushed a commit to githubmo/rubyzip that referenced this issue Jan 6, 2014
…ypt-perf

* 'master' of https://github.com/rubyzip/rubyzip:
  Explicitly add the released 2.1.0 Ruby version Remove branch restriction
  Fix Rubinius by adding newly required gems, updating label in .travis.yml
  Update README.md
  Update README.md
  Make File.open_buffer support Tempfiles
  Version bump
  Update Changelog with Ruby 1.9 requirement
  Update README to reflect 1.9 requirement
  Fix rubyzip#106 Set options about restoring ownerships, permissions and times. restore permissions enabled by default.
  fix jRuby Building rubyzip#104
  Fix rubyzip#28 and rubyzip#103
  disable jRuby for a while
  Fix rubyzip#102 recover file permissions if zip file was exist
  Add missing Zip::Entry arguments to Zip::File#get_output_stream. Fixes rubyzip#100
  fix string encoding of zip64 header ids for ruby 2.0
  Add read/write support for zip64 extensions

Conflicts:
	lib/zip/extra_field.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants