From 792266dbf3f85773d82976a441a59fcbf895ff5e Mon Sep 17 00:00:00 2001 From: Phil Date: Wed, 21 Feb 2018 11:48:56 -0800 Subject: [PATCH] Added fix for calling 'close' on a StringIO-backed zip file, and specs --- lib/zip/file.rb | 2 +- test/file_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/zip/file.rb b/lib/zip/file.rb index 4bc3edc4..6952ba99 100644 --- a/lib/zip/file.rb +++ b/lib/zip/file.rb @@ -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| diff --git a/test/file_test.rb b/test/file_test.rb index 73f60af5..32e21e33 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -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