appendRemaining
Transfers all bytes from the current position to the end of the stream, up
to limit, appending them to list.
If limit is reached or exceeded, error.StreamTooLong is returned
instead. In such case, the next byte that would be read will be the first
one to exceed limit, and all preceeding bytes have been appended to
list.
See also:
allocRemaining
Function parameters
Parameters
Type definitions in this namespace
Types
Functions in this namespace
Functions
- fixed
- Constructs a `Reader` such that it will read from `buffer` and then end.
- streamExact
- "Pump" exactly `n` bytes from the reader to the writer.
- streamExact64
- "Pump" exactly `n` bytes from the reader to the writer.
- streamExactPreserve
- "Pump" exactly `n` bytes from the reader to the writer.
- streamRemaining
- "Pump" data from the reader to the writer, handling `error.EndOfStream` as
- discardRemaining
- Consumes the stream until the end, ignoring all the data, returning the
- allocRemaining
- Transfers all bytes from the current position to the end of the stream, up
- appendRemaining
- Transfers all bytes from the current position to the end of the stream, up
- readVec
- Writes bytes from the internally tracked stream position to `data`.
- defaultReadVec
- Writes to `Reader.buffer` or `data`, whichever has larger capacity.
- peek
- Returns the next `len` bytes from the stream, filling the buffer as
- peekGreedy
- Returns all the next buffered bytes, after filling the buffer to ensure it
- toss
- Skips the next `n` bytes from the stream, advancing the seek position.
- tossBuffered
- Equivalent to `toss(r.bufferedLen())`.
- take
- Equivalent to `peek` followed by `toss`.
- takeArray
- Returns the next `n` bytes from the stream as an array, filling the buffer
- peekArray
- Returns the next `n` bytes from the stream as an array, filling the buffer
- discardAll
- Skips the next `n` bytes from the stream, advancing the seek position.
- discardShort
- Skips the next `n` bytes from the stream, advancing the seek position.
- readSliceAll
- Fill `buffer` with the next `buffer.len` bytes from the stream, advancing
- readSliceShort
- Fill `buffer` with the next `buffer.len` bytes from the stream, advancing
- readSliceEndian
- Fill `buffer` with the next `buffer.len` bytes from the stream, advancing
- readSliceEndianAlloc
- The function is inline to avoid the dead code in case `endian` is
- readAlloc
- Shortcut for calling `readSliceAll` with a buffer provided by `allocator`.
- takeSentinel
- Returns a slice of the next bytes of buffered data from the stream until
- peekSentinel
- Returns a slice of the next bytes of buffered data from the stream until
- takeDelimiterInclusive
- Returns a slice of the next bytes of buffered data from the stream until
- peekDelimiterInclusive
- Returns a slice of the next bytes of buffered data from the stream until
- takeDelimiterExclusive
- Returns a slice of the next bytes of buffered data from the stream until
- takeDelimiter
- Returns a slice of the next bytes of buffered data from the stream until
- peekDelimiterExclusive
- Returns a slice of the next bytes of buffered data from the stream until
- streamDelimiter
- Appends to `w` contents by reading from the stream until `delimiter` is
- streamDelimiterEnding
- Appends to `w` contents by reading from the stream until `delimiter` is found.
- streamDelimiterLimit
- Appends to `w` contents by reading from the stream until `delimiter` is found.
- discardDelimiterInclusive
- Reads from the stream until specified byte is found, discarding all data,
- discardDelimiterExclusive
- Reads from the stream until specified byte is found, discarding all data,
- discardDelimiterLimit
- Reads from the stream until specified byte is found, discarding all data,
- fill
- Fills the buffer such that it contains at least `n` bytes, without
- fillMore
- Without advancing the seek position, does exactly one underlying read, filling the buffer as
- peekByte
- Returns the next byte from the stream or returns `error.EndOfStream`.
- takeByte
- Reads 1 byte from the stream or returns `error.EndOfStream`.
- takeByteSigned
- Same as `takeByte` except the returned byte is signed.
- takeInt
- Asserts the buffer was initialized with a capacity at least `@bitSizeOf(T) / 8`.
- peekInt
- Asserts the buffer was initialized with a capacity at least `@bitSizeOf(T) / 8`.
- takeVarInt
- Asserts the buffer was initialized with a capacity at least `n`.
- takeStructPointer
- Obtains an unaligned pointer to the beginning of the stream, reinterpreted
- peekStructPointer
- Obtains an unaligned pointer to the beginning of the stream, reinterpreted
- takeStruct
- Asserts the buffer was initialized with a capacity at least `@sizeOf(T)`.
- peekStruct
- Asserts the buffer was initialized with a capacity at least `@sizeOf(T)`.
- takeEnum
- Reads an integer with the same size as the given enum's tag type.
- takeEnumNonexhaustive
- Reads an integer with the same size as the given nonexhaustive enum's tag type.
- takeLeb128
- Read a single LEB128 value as type T, or `error.Overflow` if the value cannot fit.
- rebase
- Ensures `capacity` data can be buffered without rebasing.
- Hashed
- Provides a `Reader` implementation by passing data from an underlying
Error sets in this namespace
Error Sets
= .{ .vtable = &.{ .stream = failingStream, .discard = failingDiscard, }, .buffer = &.{}, .seek = 0, .end = 0, }
Values
Source
Implementation
pub fn appendRemaining(
r: *Reader,
gpa: Allocator,
list: *ArrayList(u8),
limit: Limit,
) LimitedAllocError!void {
var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.items);
a.writer.end = list.items.len;
list.* = .empty;
defer {
list.* = .{
.items = a.writer.buffer[0..a.writer.end],
.capacity = a.writer.buffer.len,
};
}
var remaining = limit;
while (remaining.nonzero()) {
const n = stream(r, &a.writer, remaining) catch |err| switch (err) {
error.EndOfStream => return,
error.WriteFailed => return error.OutOfMemory,
error.ReadFailed => return error.ReadFailed,
};
remaining = remaining.subtract(n).?;
}
return error.StreamTooLong;
}