Skip to content

Commit

Permalink
Set OutputStream.write_buffer's default buffer to binmode
Browse files Browse the repository at this point in the history
  • Loading branch information
henkesn committed Feb 19, 2020
1 parent 8d91d00 commit f0526d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/zip/output_stream.rb
Expand Up @@ -57,7 +57,7 @@ def open(file_name, encrypter = nil)
end

# Same as #open but writes to a filestream instead
def write_buffer(io = ::StringIO.new(''), encrypter = nil)
def write_buffer(io = ::StringIO.new('').binmode, encrypter = nil)
zos = new(io, true, encrypter)
yield zos
zos.close_buffer
Expand Down
10 changes: 10 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'

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

def test_write_buffer_binmode
buffer = ::Zip::OutputStream.write_buffer do |zos|
zos.comment = TEST_ZIP.comment
write_test_zip(zos)
end
assert buffer.external_encoding.name === ASCII8BIT
end

def test_write_buffer_with_temp_file
tmp_file = Tempfile.new('')

Expand Down

0 comments on commit f0526d7

Please sign in to comment.