-
Notifications
You must be signed in to change notification settings - Fork 27
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
Avoid double counting in stats
out
when writing to nested streams
#204
Conversation
changemode!(stream, :write) | ||
if marginsize(stream.buffer1) == 0 && flushbuffer(stream) == 0 | ||
return 0 |
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.
write
will throw an error instead of returning 0 on failure.
src/stream.jl
Outdated
buffer1 = stream.buffer1 | ||
p = input | ||
p_end = p + nbytes | ||
while p < p_end && (marginsize(buffer1) > 0 || flushbuffer(stream) > 0) | ||
while p < p_end | ||
marginsize(buffer1) > 0 || flush_buffer1(stream) |
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.
flush_buffer1
must empty buffer1
or error, so this loop should make progress.
@@ -595,9 +595,12 @@ function stats(stream::TranscodingStream) | |||
out = transcoded_out - buffersize(buffer1) | |||
elseif mode === :write | |||
transcoded_in = buffer1.transcoded | |||
transcoded_out = buffer2.transcoded |
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.
buffer2
is "owned" by the underlying stream if it is shared, so this stream shouldn't rely on buffer2.transcoding
being the expected value.
@reallyasi9 Thank you for updating ZipStreams.jl for this fix. I'll merge this PR sometime next week unless there are other concerns. |
Here is an example of the bug this PR fixes:
Before this PR this would output 12 even though only 6 bytes were written to the underlying stream.