Skip to content

provide a peeking API to std.io.BufferedReader #4501

@andrewrk

Description

@andrewrk

The point of BufferedInStream is to call read() on the underlying stream in bursts, rather than separate calls. E.g. to make 1 syscall to read() reading 999 bytes, rather than 999 syscalls to read() 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_space or something like this, and then it's guaranteed to be able to "put back" this many elements.

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions