-
-
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
Feature Request: peek(io::IO, x) #2638
Comments
All we have so far is |
I thought I had seen these when I implemented gzip support, but missed them this time because they aren't exported. Right now, for Unfortunately, returning -1 doesn't generalize. The obvious solution is to throw an Thoughts? CC: @vtjnash |
Ah yes, the fact that they're not exported probably means I wasn't happy with the API. There is also a reason why very few (any?) environments have |
A google search revealed the following:
http://docs.python.org/2/library/io.html#buffered-streams
http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#mark(int) I think I like the java version, but not sure about the implications. Thoughts? |
Actually, either way would be fine. The python version is nice in that it's simple, and closer in spirit to julia. |
The Java implementation seems much cooler to me, since you don't need to reimplement all of the read methods. In python, everything is just a string buffer, so it's not really a problem to peek N bytes and then parse. In Julia, it seems better to me to be able to do multi-type reads (like Java) without needing to create a separate read-ahead/peek buffer. The Java-like implementation could even give you file-like seek access on a stream, by expressing locations relative to the mark. |
That's fine--I'm okay with either one. I'll work on it. |
The Java mark interface does seem rather nice. I can see having to specify a limit beforehand as being constraining sometimes, however. If we add a mark(io) do
# can reset io in here
end In fact, that kind of makes me wonder if it wouldn't make more sense to simply wrap the bare |
A wrapper was what I was leaning toward. Perhaps there could be two versions, one with a fixed buffer size, and one which spills to disk after the buffer fills (for non-file streams). |
RFM: mark/reset for IOStream, IOBuffer, & AsyncStream (addresses #2638)
This can be closed now that #3656 is merged. |
As discussed here: https://groups.google.com/forum/?fromgroups=#!topic/julia-users/kDKL1dS4L0w
Basically, I'd like to be able to peek at the first few characters of an IO stream, without removing the characters from the stream. In particular, it needs to work with streams that are not files and therefore not seekable.
The text was updated successfully, but these errors were encountered: