ZnBufferedReadStream can read incorrectly after moving position back
Closed this issue · 3 comments
Rinzwind commented
In the following example, the last #next
message unexpectedly answers 1 rather than 2:
(byteArray := ByteArray new: 1 + 65535 + 32768 withAll: 0)
at: 1 put: 1;
at: 1 + 32768 put: 2.
(ZnBufferedReadStream on: byteArray readStream)
next;
next: 65535 + 32768;
position: 32768;
next
This is because #position:
assumes that the buffer’s end corresponds to the current position of the stream, which is invalidated by the case in which #shouldBufferReadOfCount:
answers false in #readInto:startingAt:count:
as that advances the stream while not reading into the buffer. So it would seem that either the first method should be fixed to use the buffer’s end as determined when the buffer was read, or the case in the second method should be made to reset the buffer.
svenvc commented
Rinzwind commented
Thanks, seems fine!
svenvc commented
Thanks, Kris, the fix was pushed