Skip to content

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

@mdesantis

Description

@mdesantis

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

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy