-
Notifications
You must be signed in to change notification settings - Fork 317
Closed
Description
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
Labels
No labels