# ByteReader

`import { ByteReader } from "destack:bytes";`

Sequential byte reader over in-memory bytes.

```ds title="ByteReader"
export class ByteReader {
    bytes: Bytes;
    offset: usize;
    static from(bytes: readonly [uint8]): ^ByteReader;
    size(): usize;
    position(): usize;
    remaining(): usize;
    isEmpty(): boolean;
    seek(offset: usize): void;
    skip(count: usize): usize;
    peekByte(): uint8 | undefined;
    readByte(): uint8 | undefined;
    unreadByte(): void;
    read(length: usize): readonly [uint8];
    readExact(length: usize): Bytes | undefined;
    readUntil(delimiter: uint8): Bytes | undefined;
    readToEnd(): readonly [uint8];
}
```

[language/library/src/bytes/reader.ds:6:87](https://github.com/destack-sh/destack/blob/main/language/library/src/bytes/reader.ds#L6-L87)

## Members

### `bytes: Bytes`

The source bytes.

### `offset: usize`

The current byte offset.

### `static from(bytes: readonly [uint8]): ^ByteReader`

Create a reader for `bytes`.

### `size(): usize`

Return the total byte count.

### `position(): usize`

Return the current byte offset.

### `remaining(): usize`

Return the unread byte count.

### `isEmpty(): boolean`

Return whether no unread bytes remain.

### `seek(offset: usize): void`

Move the current byte offset.

### `skip(count: usize): usize`

Skip up to `count` bytes.

### `peekByte(): uint8 | undefined`

Return the next byte without advancing.

### `readByte(): uint8 | undefined`

Read one byte.

### `unreadByte(): void`

Step back by one byte.

### `read(length: usize): readonly [uint8]`

Read at most `length` bytes.

### `readExact(length: usize): Bytes | undefined`

Read exactly `length` bytes.

### `readUntil(delimiter: uint8): Bytes | undefined`

Read bytes until `delimiter` is consumed.

### `readToEnd(): readonly [uint8]`

Read all remaining bytes.
