Skip to content

Commit

Permalink
Merge pull request #439 from henkeinfo/binary-outstream-buffer
Browse files Browse the repository at this point in the history
Set OutputStream.write_buffer's default buffer to binmode
  • Loading branch information
jdleesmiller committed Mar 14, 2020
2 parents 8d91d00 + 66324a7 commit b231b28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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'

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

0 comments on commit b231b28

Please sign in to comment.