Accept StringIO in Zip.open_buffer.

This commit is contained in:
Victor Costan 2015-07-02 14:17:17 -04:00
parent 228cd4a74f
commit 37a5baad96
2 changed files with 9 additions and 2 deletions

View File

@ -115,8 +115,8 @@ module Zip
# (This can be used to extract data from a
# downloaded zip archive without first saving it to disk.)
def open_buffer(io, options = {})
unless io.is_a?(IO) || io.is_a?(String) || io.is_a?(Tempfile)
raise "Zip::File.open_buffer expects an argument of class String, IO, or Tempfile. Found: #{io.class}"
unless io.is_a?(IO) || io.is_a?(String) || io.is_a?(Tempfile) || io.is_a?(StringIO)
raise "Zip::File.open_buffer expects an argument of class String, IO, StringIO, or Tempfile. Found: #{io.class}"
end
if io.is_a?(::String)
require 'stringio'

View File

@ -82,6 +82,13 @@ class ZipFileTest < MiniTest::Test
end
end
def test_open_buffer_with_stringio
string_io = StringIO.new File.read('test/data/rubycode.zip')
::Zip::File.open_buffer string_io do |zf|
assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb')
end
end
def test_cleans_up_tempfiles_after_close
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
zf.get_output_stream('myFile') do |os|