Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fix for calling 'close' on a StringIO-backed zip file, and specs #353

Merged
merged 1 commit into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/zip/file.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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