-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Document and export Base.peek #28811
Conversation
Does it work on all kinds of I/O streams now? |
Maybe? I didn't change any methods, but there is a method already there for |
@Keno, you recently added some methods to |
There is a generic method: Lines 513 to 519 in e4d933d
But it depends on |
I am guessing we do not want to export a new API here. Please suggest to merge or close. Since this changes the export, I'll remove the doc label (since it's not strictly a doc PR). |
I think |
I think the API should be that |
Found a spare couple of minutes for a rebase. |
I'm having trouble seeing where |
I changed it to |
I noticed that |
Ah, that seems bad. Does it actually read/return 32-bits of data or just a byte cast to Int32? |
It's doing a julia> open(io -> print(io, "こんにちは"), "thing", "w")
julia> open(Base.peek, "thing", "r")
227 |
So in C it's traditional to return an |
Something like the definition of |
Exactly. |
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.
This is a really nice bit of API rationalization and making peek
coherent enough to export. Thank you! Might be good for @JeffBezanson to take a look since he's got a good eye for details I may have missed.
@@ -1193,9 +1193,9 @@ unmark(x::LibuvStream) = unmark(x.buffer) | |||
reset(x::LibuvStream) = reset(x.buffer) | |||
ismarked(x::LibuvStream) = ismarked(x.buffer) | |||
|
|||
function peek(s::LibuvStream) | |||
function peek(s::LibuvStream, ::Type{T}) where T |
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.
Seems to be identical to the fallback method. Not a problem though.
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.
Yeah, I noticed that. Figured I'd punt on dealing with that though, just in case there was something I was missing.
I'm a little concerned that the default |
In io.jl around line 354 there's a for loop that defines another |
I had the same thought: the efficient way to do this is to add support for peeking four bytes at a time and then decoding a UTF-8 character from that. |
It's generally useful but is currently both undocumented and unexported.
Thanks everyone! Always fun to revisit a nearly 2 year old PR and get it merged. :) |
added import from `Base`. Reason : JuliaLang/julia#28811
It's generally useful but is currently both undocumented and unexported.
Closes #28797.