Switch newly created StringIOs to binmode.
StringIO objects created within File.open_buffer were not being switched into binmode, but those passed in were. Fix this inconsistency and add a test.
This commit is contained in:
parent
15ccc25da1
commit
84c208982f
|
@ -134,12 +134,10 @@ module Zip
|
||||||
raise "Zip::File.open_buffer expects a String or IO-like argument (responds to #{IO_METHODS.join(', ')}). Found: #{io.class}"
|
raise "Zip::File.open_buffer expects a String or IO-like argument (responds to #{IO_METHODS.join(', ')}). Found: #{io.class}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if io.is_a?(::String)
|
io = ::StringIO.new(io) if io.is_a?(::String)
|
||||||
io = ::StringIO.new(io)
|
|
||||||
elsif io.respond_to?(:binmode)
|
|
||||||
# https://github.com/rubyzip/rubyzip/issues/119
|
# https://github.com/rubyzip/rubyzip/issues/119
|
||||||
io.binmode
|
io.binmode if io.respond_to?(:binmode)
|
||||||
end
|
|
||||||
|
|
||||||
zf = ::Zip::File.new(io, true, true, options)
|
zf = ::Zip::File.new(io, true, true, options)
|
||||||
return zf unless block_given?
|
return zf unless block_given?
|
||||||
|
|
|
@ -97,6 +97,13 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_open_buffer_with_string
|
||||||
|
string = File.read('test/data/rubycode.zip')
|
||||||
|
::Zip::File.open_buffer string do |zf|
|
||||||
|
assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_open_buffer_with_stringio
|
def test_open_buffer_with_stringio
|
||||||
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
||||||
::Zip::File.open_buffer string_io do |zf|
|
::Zip::File.open_buffer string_io do |zf|
|
||||||
|
|
Loading…
Reference in New Issue