Skip to content

Commit

Permalink
Added fix for calling 'close' on a StringIO-backed zip file, and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
pnomolos committed Feb 21, 2018
1 parent 2f80da6 commit 792266d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/zip/file.rb
Expand Up @@ -306,7 +306,7 @@ def extract(entry, dest_path, &block)
# Commits changes that has been made since the previous commit to
# the zip archive.
def commit
return unless commit_required?
return if name.is_a?(StringIO) || !commit_required?
on_success_replace do |tmp_file|
::Zip::OutputStream.open(tmp_file) do |zos|
@entry_set.each do |e|
Expand Down
13 changes: 13 additions & 0 deletions test/file_test.rb
Expand Up @@ -104,6 +104,19 @@ def test_open_buffer_with_stringio
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
string_io = StringIO.new File.read('test/data/rubycode.zip')
zf = ::Zip::File.open_buffer string_io
Expand Down

0 comments on commit 792266d

Please sign in to comment.