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

Allow Tempfile as IO for OutputStream::write_buffer #182

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/zip/output_stream.rb
Expand Up @@ -29,7 +29,6 @@ def initialize(file_name, stream=false)
@file_name = file_name
@output_stream = if stream
iostream = @file_name.dup
iostream.reopen
iostream.rewind
iostream
else
Expand Down
15 changes: 15 additions & 0 deletions test/output_stream_test.rb
Expand Up @@ -32,6 +32,21 @@ def test_write_buffer
assert_test_zip_contents(TEST_ZIP)
end

def test_write_buffer_with_temp_file
tmp_file = Tempfile.new('')

::Zip::OutputStream.write_buffer(tmp_file) do |zos|
zos.comment = TEST_ZIP.comment
write_test_zip(zos)
end

tmp_file.rewind
File.open(TEST_ZIP.zip_name, 'wb') { |f| f.write(tmp_file.read) }
tmp_file.unlink

assert_test_zip_contents(TEST_ZIP)
end

def test_writingToClosedStream
assert_i_o_error_in_closed_stream { |zos| zos << "hello world" }
assert_i_o_error_in_closed_stream { |zos| zos.puts "hello world" }
Expand Down