HomePhorge

(PUP-2946) Ensure #compare_stream uses binary strings
8d452e944299Unpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

(PUP-2946) Ensure #compare_stream uses binary strings

In Ruby commit 2142287c FileUtils.compare_stream was optimized to
produce fewer objects while comparing streams by predeclaring a pair of
strings and reusing them for each iteration of the comparison. However,
this change exposes some inconsistency in how ruby handles IO#read vs
StringIO#read. When IO#read is passed a length and string, it will copy
the read data into the string, but will convert the encoding from the
expected ASCII-8BIT into the encoding of the string regardless of if the
file was opened as a binary file. However, when StringIO#read is passed
a length and string it will convert the passed string to the expected
ASCII-8BIT. Because of this it's impossible to use FileUtils.compare_stream
to compare a binary file and StringIO instance.

To resolve this issue, this commit adds a custom compare_stream method
which sets the encoding of the strings to always be ASCII-8BIT on Ruby
1.9+.

Details

Provenance
Adrien Thebo <git@somethingsinistral.net>Authored on
vanmeeuwenPushed on Jun 2 2015, 2:22 PM
Parents
rPUc6ba27e2c419: Merge pull request #2934 from peterhuene/pup/2971
Branches
Unknown
Tags
Unknown

Event Timeline

Adrien Thebo <git@somethingsinistral.net> committed rPU8d452e944299: (PUP-2946) Ensure #compare_stream uses binary strings (authored by Adrien Thebo <git@somethingsinistral.net>).Aug 7 2014, 11:08 PM