-
Notifications
You must be signed in to change notification settings - Fork 19
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
Buffer encoding #19
Buffer encoding #19
Changes from 5 commits
2a86ded
621e18e
3d97b83
9a1b911
3bc3787
f08d80c
eeff06c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ group :test do | |
end | ||
|
||
group :doc do | ||
gem "redcarpet" | ||
gem "redcarpet", platform: :mri | ||
gem "yard" | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ class CompositeIO | |
# @param [Array<IO>] ios Array of IO objects | ||
def initialize(ios) | ||
@index = 0 | ||
@buffer = String.new | ||
@buffer = "".b | ||
@ios = ios.map do |io| | ||
if io.is_a?(String) | ||
StringIO.new(io) | ||
|
@@ -29,14 +29,16 @@ def initialize(ios) | |
# | ||
# @return [String, nil] | ||
def read(length = nil, outbuf = nil) | ||
outbuf = outbuf.to_s.replace("") | ||
outbuf = outbuf.to_s.clear | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though this is likely a bug in the previous version as well, Perhaps give outbuf a default value (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #to_s will not create a new object if the object is a string. But the replace call might change its encoding. That was the reasoning behind it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hence "may make a new object". We never want to make a new object for the buffer... that defeats the point. How about raising if the supplied buffer is not a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ahh, I see what you mean.
I'm still not sure. The encoding requirement is usually not mandatory, and the buffer passed may be a specialized buffer. Besides "fixing" jruby, I'm not even sure that forcing binary encoding there is the right thing to do. By the way, what's the reasoning behind allowing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In what case would it make sense for it to be anything but a
For these types of buffers, I think mandating For other encodings there are all sorts of pathological performance implications, and the contract at this point in the code is to handle arbitrary binary data that may not be whatever-encoding-was-passed-in. Given this is a rarely used power-user feature, I think it should have some pretty exacting semantics, which are:
No idea, like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with this change, I'll try to answer the questions below. |
||
# buffer in JRuby is sometimes US-ASCII, force to ASCII-8BIT | ||
outbuf.force_encoding(Encoding::BINARY) | ||
|
||
while current_io | ||
current_io.read(length, @buffer) | ||
outbuf << @buffer | ||
|
||
if length | ||
length -= @buffer.length | ||
length -= @buffer.bytesize | ||
break if length.zero? | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis CI is blowing up on this line, because Rubocop for the project is requiring hash rockets. I am guessing that's a personal preference for the project, as I prefer Ruby 1.9+ colon syntax...