DoxigAlpha

readAllArrayListAligned

Function parameters

Parameters

#
alignment:?Alignment
array_list:*std.array_list.AlignedManaged(u8, alignment)
max_append_size:usize

Optional parameters for `skipBytes`

Types

#
SkipBytesOptions
Optional parameters for `skipBytes`

Returns the number of bytes read.

Functions

#
read
Returns the number of bytes read.
readAll
Returns the number of bytes read.
readAtLeast
Returns the number of bytes read, calling the underlying read
readNoEof
If the number read would be smaller than `buf.len`, `error.EndOfStream` is returned instead.
readAllArrayList
Appends to the `std.array_list.Managed` contents by reading from the stream
readAllAlloc
Allocates enough memory to hold all the contents of the stream.
readUntilDelimiterArrayList
Deprecated: use `streamUntilDelimiter` with ArrayList's writer instead.
readUntilDelimiterAlloc
Deprecated: use `streamUntilDelimiter` with ArrayList's writer instead.
readUntilDelimiter
Deprecated: use `streamUntilDelimiter` with FixedBufferStream's writer instead.
readUntilDelimiterOrEofAlloc
Deprecated: use `streamUntilDelimiter` with ArrayList's (or any other's) writer instead.
readUntilDelimiterOrEof
Deprecated: use `streamUntilDelimiter` with FixedBufferStream's writer instead.
streamUntilDelimiter
Appends to the `writer` contents by reading from the stream until `delimiter` is found.
skipUntilDelimiterOrEof
Reads from the stream until specified byte is found, discarding all data,
readByte
Reads 1 byte from the stream or returns `error.EndOfStream`.
readByteSigned
Same as `readByte` except the returned byte is signed.
readBytesNoEof
Reads exactly `num_bytes` bytes and returns as an array.
skipBytes
Reads `num_bytes` bytes from the stream and discards them
isBytes
Reads `slice.len` bytes from the stream and returns if they are the same as the passed slice
readEnum
Reads an integer with the same size as the given enum's tag type.
discard
Reads the stream until the end, ignoring all the data.
adaptToNewApi
Helper for bridging to the new `Reader` API while upgrading.

Source

Implementation

#
pub fn readAllArrayListAligned(
    self: Self,
    comptime alignment: ?Alignment,
    array_list: *std.array_list.AlignedManaged(u8, alignment),
    max_append_size: usize,
) anyerror!void {
    try array_list.ensureTotalCapacity(@min(max_append_size, 4096));
    const original_len = array_list.items.len;
    var start_index: usize = original_len;
    while (true) {
        array_list.expandToCapacity();
        const dest_slice = array_list.items[start_index..];
        const bytes_read = try self.readAll(dest_slice);
        start_index += bytes_read;

        if (start_index - original_len > max_append_size) {
            array_list.shrinkAndFree(original_len + max_append_size);
            return error.StreamTooLong;
        }

        if (bytes_read != dest_slice.len) {
            array_list.shrinkAndFree(start_index);
            return;
        }

        // This will trigger ArrayList to expand superlinearly at whatever its growth rate is.
        try array_list.ensureTotalCapacity(start_index + 1);
    }
}