Merge pull request #353 from pnomolos/pnomolos/fix_stringio

Added fix for calling 'close' on a StringIO-backed zip file, and specs
This commit is contained in:
Oleksandr Simonov 2018-03-30 16:58:27 +03:00 committed by GitHub
commit 05af1231f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -306,7 +306,7 @@ module Zip
# Commits changes that has been made since the previous commit to # Commits changes that has been made since the previous commit to
# the zip archive. # the zip archive.
def commit def commit
return unless commit_required? return if name.is_a?(StringIO) || !commit_required?
on_success_replace do |tmp_file| on_success_replace do |tmp_file|
::Zip::OutputStream.open(tmp_file) do |zos| ::Zip::OutputStream.open(tmp_file) do |zos|
@entry_set.each do |e| @entry_set.each do |e|

View File

@ -104,6 +104,19 @@ class ZipFileTest < MiniTest::Test
end end
end end
def test_close_buffer_with_stringio
string_io = StringIO.new File.read('test/data/rubycode.zip')
zf = ::Zip::File.open_buffer string_io
assert(zf.close || true) # Poor man's refute_raises
end
def test_close_buffer_with_io
f = File.open('test/data/rubycode.zip')
zf = ::Zip::File.open_buffer f
assert zf.close
f.close
end
def test_open_buffer_without_block def test_open_buffer_without_block
string_io = StringIO.new File.read('test/data/rubycode.zip') string_io = StringIO.new File.read('test/data/rubycode.zip')
zf = ::Zip::File.open_buffer string_io zf = ::Zip::File.open_buffer string_io