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

std.io: PeekStream and SliceStream #1282

Merged
merged 1 commit into from Jul 24, 2018
Merged

std.io: PeekStream and SliceStream #1282

merged 1 commit into from Jul 24, 2018

Conversation

nwsharp
Copy link
Contributor

@nwsharp nwsharp commented Jul 24, 2018

SliceStream is a read-only stream wrapper around a slice of bytes. It
allows adapting algorithms which work on InStreams to in-memory data.

PeekStream is a stream wrapper which allows "putting back" bytes into
the stream so that they can be read again. This will help make
look-ahead parsers easier to write.

I wrote PeekStream to help with parsing IEEE-754 floats, and I wrote SliceStream to help me test PeekStream.

In C++-land, SliceStream is sort of like an std::istringstream, and PeekStream is like std::basic_istream::putback(). Both are useful enough on their own to be in the standard library, IMHO.

Though std.io might not be the right place. It's getting sort of cluttered in there. Maybe make an std.streams module?

SliceStream is a read-only stream wrapper around a slice of bytes. It
allows adapting algorithms which work on InStreams to in-memory data.

PeekStream is a stream wrapper which allows "putting back" bytes into
the stream so that they can be read again. This will help make
look-ahead parsers easier to write.
@tiehuis
Copy link
Member

tiehuis commented Jul 24, 2018

Looks good to me. I agree that these are useful additions. I had a custom MemoryStream I was using in some code so this will be a good replacement.

I think std.io is okay for the moment. std is in flux until 1.0.0 anyway so we can reshuffle things as we get a better idea of what is useful and where things should lie.

@andrewrk andrewrk merged commit 74c80d2 into ziglang:master Jul 24, 2018
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.

None yet

3 participants