-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
provide a peeking API to std.io.BufferedReader #4501
Copy link
Copy link
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
The point of BufferedInStream is to call
read()on the underlying stream in bursts, rather than separate calls. E.g. to make 1 syscall toread()reading 999 bytes, rather than 999 syscalls toread()reading 1 byte each.The point of PeekStream is to be able to "put back" bytes, so that the next call to
read()will get them again. In order to accomplish this, PeekStream needs a buffer. That makes PeekStream also a BufferedInStream.All we need to unify these two APIs is for BufferedInStream to have a parameter called
reserved_buffer_spaceor something like this, and then it's guaranteed to be able to "put back" this many elements.Related: