Skip to content

Commit

Permalink
Merge pull request #201 from mcantor/master
Browse files Browse the repository at this point in the history
Be smarter about handling buffer file modes
  • Loading branch information
simonoff committed Jan 17, 2015
2 parents 9e7af06 + 7c7d786 commit 721c1f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/zip/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,18 @@ def open_buffer(io, options = {})
if io.is_a?(::String)
require 'stringio'
io = ::StringIO.new(io)
elsif io.is_a?(IO)
# https://github.com/rubyzip/rubyzip/issues/119
io.binmode
end
zf = ::Zip::File.new(io, true, true, options)
zf.read_from_stream(io)
yield zf
zf.write_buffer(io)
begin
zf.write_buffer(io)
rescue IOError => e
raise unless e.message == "not opened for writing"
end
end

# Iterates over the contents of the ZipFile. This is more efficient
Expand Down
2 changes: 1 addition & 1 deletion lib/zip/output_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(file_name, stream=false, encrypter=nil)
@file_name = file_name
@output_stream = if stream
iostream = @file_name.dup
iostream.reopen
iostream.reopen(@file_name)
iostream.rewind
iostream
else
Expand Down

0 comments on commit 721c1f0

Please sign in to comment.