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

Set OutputStream.write_buffer's default buffer to binmode #439

Merged
merged 3 commits into from Mar 14, 2020
Merged
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: 1 addition & 0 deletions lib/zip/output_stream.rb
Expand Up @@ -58,6 +58,7 @@ def open(file_name, encrypter = nil)

# Same as #open but writes to a filestream instead
def write_buffer(io = ::StringIO.new(''), encrypter = nil)
io.binmode if io.respond_to?(:binmode)
zos = new(io, true, encrypter)
yield zos
zos.close_buffer
Expand Down
11 changes: 11 additions & 0 deletions test/output_stream_test.rb
Expand Up @@ -6,6 +6,8 @@ class ZipOutputStreamTest < MiniTest::Test
TEST_ZIP = TestZipFile::TEST_ZIP2.clone
TEST_ZIP.zip_name = 'test/data/generated/output.zip'

ASCII8BIT = 'ASCII-8BIT'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant can now be removed, but I'll tidy it up post-merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx!


def test_new
zos = ::Zip::OutputStream.new(TEST_ZIP.zip_name)
zos.comment = TEST_ZIP.comment
Expand All @@ -32,6 +34,15 @@ def test_write_buffer
assert_test_zip_contents(TEST_ZIP)
end

def test_write_buffer_binmode
io = ::StringIO.new('')
buffer = ::Zip::OutputStream.write_buffer(io) do |zos|
zos.comment = TEST_ZIP.comment
write_test_zip(zos)
end
assert_equal Encoding::ASCII_8BIT, buffer.external_encoding
end

def test_write_buffer_with_temp_file
tmp_file = Tempfile.new('')

Expand Down