Skip to content

Commit

Permalink
Accept StringIO in Zip.open_buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnall committed Jul 2, 2015
1 parent 228cd4a commit 37a5baa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/zip/file.rb
Expand Up @@ -115,8 +115,8 @@ def add_buffer
# (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'
Expand Down
7 changes: 7 additions & 0 deletions test/file_test.rb
Expand Up @@ -82,6 +82,13 @@ def test_get_output_stream
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|
Expand Down

0 comments on commit 37a5baa

Please sign in to comment.