Skip to content
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

add peek(io, UInt8) and peek(io, Char) (#16025) #16181

Closed
wants to merge 1 commit into from

Conversation

bicycle1885
Copy link
Member

This pull request adds and exports peek from Base, and will close #16025. This works on AbstractIOBuffer and IOStream; more generic definition will be possible if the IO type supports seek.

io = open(n)
write(w, "A"); flush(w)
@test peek(io, UInt8) === 0x41
@test peek(io, Char) === 'A'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also test with a non-ASCII char?

@nalimilan
Copy link
Member

Thanks, looks good! You should run make julia-genstdlib to update the docs. You should also add peek to doc/stdlib/io-network.rst (and maybe mention it in the manual too).

@nalimilan
Copy link
Member

nalimilan commented May 8, 2016

The tests failure is due to priorityqueue.jl having using Base.Collections, and Base.Collections having a peek function. Not sure how to best handle that. Note that it also has an eval function; so that's not a new issue.

@laborg
Copy link
Contributor

laborg commented Feb 3, 2022

This has been implemented. See #28811

On Julia 1.7.1:

julia> using Test

julia> let n = tempname()
           w = open(n, "a")
           io = open(n)
           write(w, "A"); flush(w)
           @test peek(io, UInt8) === 0x41
           @test peek(io, Char) === 'A'
           read(io, UInt8)
           @test_throws EOFError peek(io, UInt8)
           @test_throws EOFError peek(io, Char)
           close(io); close(w)
           rm(n)
       end

succeeds.

@laborg laborg closed this Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

modify Base.peek to return a Char and export it
3 participants