-
Notifications
You must be signed in to change notification settings - Fork 20
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
peek resets the anchor #63
Comments
I can't reproduce your test case. The final line gives julia> isanchored(stream)
true for me.
Why is this a problem? |
It breaks the usecase where takeanchored! can be used to extract tokens from a stream as the anchor position should always be kept in the buffer. |
Actually, I take it back. As I said, I can't reproduce the problem you reported above. I also don't have any problem in cases where the buffer needs to be refilled: julia> io = BufferedInputStream(IOBuffer("foobarbaz"), 3)
BufferedInputStream{IOBuffer}(<3 B buffer, 0% filled>)
julia> peek(io)
0x66
julia> anchor!(io)
1
julia> b = Vector{UInt8}(undef, 3); readbytes!(io, b); String(b)
"foo"
julia> peek(io)
0x62
julia> isanchored(io)
true
julia> b = Vector{UInt8}(undef, 3); readbytes!(io, b); String(b)
"bar"
julia> String(copy(io.buffer)) # buffer was enlarged, still contains anchored data "foo"
"foobar" Can you provide a reproducible example of your problem? |
I tried with Julia 1.7 and 1.9.2 on Linux and could no longer reproduce this issue. pkg> activate --temp
pkg> add BufferedStreams@v1.0.0
julia> begin
using BufferedStreams
t = "1asd22asdsad333adsadsad4444asdasdasd55555asdasd999999999a";
stream = BufferedInputStream(IOBuffer(Vector{UInt8}(t)),6);
numbers = []
while !eof(stream)
b = BufferedStreams.peek(stream)
if '1' <= Char(b) <= '9'
if !isanchored(stream)
anchor!(stream)
end;
elseif isanchored(stream)
append!(numbers,[String(takeanchored!(stream))])
end
read(stream, UInt8)
end
numbers
end
#6-element Vector{Any}:
#"1"
#"22"
#"333"
#"4444"
#"55555"
#"999999999"
|
I tried the anchor example found in the documentation and it does not output anything.
I also had to add the
Char
to the if statement.In addition, I noticed that peek resets the anchor.
Version:
[e1450e63] BufferedStreams v1.0.0
The text was updated successfully, but these errors were encountered: