Accept StringIO in Zip.open_buffer.
This commit is contained in:
parent
228cd4a74f
commit
37a5baad96
|
@ -115,8 +115,8 @@ module Zip
|
||||||
# (This can be used to extract data from a
|
# (This can be used to extract data from a
|
||||||
# downloaded zip archive without first saving it to disk.)
|
# downloaded zip archive without first saving it to disk.)
|
||||||
def open_buffer(io, options = {})
|
def open_buffer(io, options = {})
|
||||||
unless io.is_a?(IO) || io.is_a?(String) || io.is_a?(Tempfile)
|
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, or Tempfile. Found: #{io.class}"
|
raise "Zip::File.open_buffer expects an argument of class String, IO, StringIO, or Tempfile. Found: #{io.class}"
|
||||||
end
|
end
|
||||||
if io.is_a?(::String)
|
if io.is_a?(::String)
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
|
|
|
@ -82,6 +82,13 @@ class ZipFileTest < MiniTest::Test
|
||||||
end
|
end
|
||||||
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
|
def test_cleans_up_tempfiles_after_close
|
||||||
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
||||||
zf.get_output_stream('myFile') do |os|
|
zf.get_output_stream('myFile') do |os|
|
||||||
|
|
Loading…
Reference in New Issue