A random-access, forward-readable byte source for the streaming parser.

The streaming index builder (see streaming_index_builder.ts) reads the source sequentially into a small moving window, so a ByteSource only has to satisfy positioned reads — it never needs the whole file resident. The in-memory BufferByteSource here is for tests and the resident case; a file-descriptor source (node) or an HTTP-Range source (M4) implements the same shape without holding the file in the JS heap.

M0 keeps reads synchronous to reuse the existing synchronous parse loop unchanged. The asynchronous variant (network pull-parser) is M4.

interface ByteSource {
    byteLength: number;
    read(offset: number, length: number, into: Uint8Array<ArrayBufferLike>, intoOffset: number): number;
}

Implemented by

Properties

Methods

Properties

byteLength: number

Total length of the source in bytes.

Methods

  • Read up to length bytes starting at offset into into at intoOffset, returning the number of bytes actually copied (fewer than length only at end of source).

    Parameters

    • offset: number

      Absolute source offset to read from.

    • length: number

      Maximum number of bytes to read.

    • into: Uint8Array<ArrayBufferLike>

      Destination buffer.

    • intoOffset: number

      Offset within into to write at.

    Returns number

    The number of bytes copied.