Skip to content

ByteReader

Defined in: packages/core/src/buffer/stream/byte-reader.ts:10

A cursor over an existing Uint8Array — a sequential reader for any binary format consumed byte-by-byte or field-by-field (PEM framing, SSH wire messages, PGP packets, ASN.1 codecs, …).

Every read advances position. Nothing is copied except when a caller explicitly asks for one: read returns a view via subarray, not a copy — a caller that needs an owned copy should call .slice() on the result itself.

new ByteReader(bytes, initialPosition?): ByteReader

Defined in: packages/core/src/buffer/stream/byte-reader.ts:19

Uint8Array

The bytes to read from. Not copied — mutating bytes after construction is visible to this reader.

number = 0

Where to start reading from. Defaults to 0.

ByteReader

When initialPosition is out of bytes’ range.

get atEnd(): boolean

Defined in: packages/core/src/buffer/stream/byte-reader.ts:51

Whether every byte has been read.

boolean


get byteLength(): number

Defined in: packages/core/src/buffer/stream/byte-reader.ts:46

The total length of the underlying buffer, regardless of position.

number


get position(): number

Defined in: packages/core/src/buffer/stream/byte-reader.ts:36

The current read position, in bytes from the start of the underlying buffer.

number


get remaining(): number

Defined in: packages/core/src/buffer/stream/byte-reader.ts:41

How many bytes remain unread.

number

peekByte(): number

Defined in: packages/core/src/buffer/stream/byte-reader.ts:76

Returns the next byte without advancing position.

number

When no bytes remain.


peekRemaining(): Uint8Array

Defined in: packages/core/src/buffer/stream/byte-reader.ts:116

Returns every remaining byte as a view, without advancing position.

Uint8Array


read(count): Uint8Array

Defined in: packages/core/src/buffer/stream/byte-reader.ts:90

Reads and returns the next count bytes as a view (not a copy) into the underlying buffer, advancing position by count.

number

Uint8Array

When fewer than count bytes remain.


readByte(): number

Defined in: packages/core/src/buffer/stream/byte-reader.ts:60

Reads and returns the next byte, advancing position by one.

number

When no bytes remain.


readSubReader(count): ByteReader

Defined in: packages/core/src/buffer/stream/byte-reader.ts:111

Reads the next count bytes into a fresh, independent ByteReader positioned at its own start — for a nested, self-contained sub-structure (an ASN.1 TLV’s contents, an SSH/PGP sub-packet) that should be read without risking overrunning into what follows it.

number

ByteReader

When fewer than count bytes remain.


seek(position): void

Defined in: packages/core/src/buffer/stream/byte-reader.ts:125

Moves position to an absolute offset.

number

void

When position is out of range.