/** * @packageDocumentation In-memory IOStream backed by an array of Uint8Array chunks. */ import { ByteVector } from "../byteVector.js"; import { IOStream } from "./ioStream.js"; import { type offset_t, Position } from "./types.js"; /** * An in-memory {@link IOStream} backed by an array of `Uint8Array` chunks. * * Unlike {@link ByteVectorStream}, data is never stored as one contiguous * buffer. This is efficient when working with large media files where only * specific regions need to be modified — existing chunks can be sliced and * reused without copying the whole buffer. * * Additionally, the chunk array can be passed directly to a * {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob Blob} * constructor, enabling zero-copy export for browser environments. * * All I/O methods are async to satisfy the {@link IOStream} contract; * the underlying operations are synchronous in-memory computations. */ export declare class ChunkedByteVectorStream extends IOStream { /** The ordered list of data chunks. Empty chunks are never stored. */ private _chunks; /** Current read/write position (bytes from the start). */ private _position; /** Total byte length across all chunks. */ private _length; /** * Creates a new ChunkedByteVectorStream. * * @param data - Zero or more `Uint8Array` chunks that form the initial * content. Empty chunks are silently discarded. */ constructor(...data: Uint8Array[]); /** * Creates a ChunkedByteVectorStream from an existing array of chunks. * * This factory avoids the overhead of the spread-argument constructor when * the chunk array is already available. Empty chunks are silently discarded. * * @param chunks - The initial chunk array. */ static fromChunks(chunks: Uint8Array[]): ChunkedByteVectorStream; /** * Returns an empty string — in-memory streams have no meaningful name. */ name(): string; /** * Reads up to `length` bytes starting from the current position, spanning * chunk boundaries as needed, and advances the position. * * @param length - Maximum number of bytes to read. * @returns Resolves with a {@link ByteVector} containing the bytes read. */ readBlock(length: number): Promise; /** * Writes `data` at the current position, overwriting existing content byte * by byte across chunk boundaries and appending a new chunk if the write * extends past the end. Advances the position by `data.length`. * * @param data - The bytes to write. */ writeBlock(data: ByteVector): Promise; /** * Inserts `data` at byte offset `start`, optionally replacing `replace` * bytes of existing content. Builds a new chunk array from slices of * existing chunks to avoid unnecessary data copies. * * @param data - The bytes to insert. * @param start - Byte offset at which to begin the insertion. * @param replace - Number of existing bytes to overwrite. Defaults to 0. */ insert(data: ByteVector, start: offset_t, replace?: number): Promise; /** * Removes `length` bytes beginning at byte offset `start`. Builds a new * chunk array from slices of the existing chunks on either side of the * removed region. * * @param start - Byte offset of the first byte to remove. * @param length - Number of bytes to remove. */ removeBlock(start: offset_t, length: number): Promise; /** Returns `false` — ChunkedByteVectorStream is always writable. */ readOnly(): boolean; /** Returns `true` — ChunkedByteVectorStream is always open. */ isOpen(): boolean; /** * Moves the read/write position. * * @param offset - Number of bytes to move. * @param position - Reference point. Defaults to {@link Position.Beginning}. */ seek(offset: offset_t, position?: Position): Promise; /** Resets the stream position to the beginning. */ clear(): Promise; /** Returns the current read/write position in bytes. */ tell(): Promise; /** Returns the total number of bytes across all chunks. */ length(): Promise; /** * Truncates or zero-extends the stream to exactly `length` bytes. If the * current position exceeds the new length, it is clamped. * * @param length - The desired stream length in bytes. */ truncate(length: offset_t): Promise; /** Returns a copy of all chunks concatenated as a {@link ByteVector}. */ data(): ByteVector; /** * Returns a {@link Blob} whose parts are the individual chunks, avoiding a * full buffer copy in browser environments. * * @param mime - Optional MIME type for the Blob. */ blob(mime?: string): Blob; /** * Returns a copy of the internal chunk array. Each element is a copy of * the corresponding chunk. */ chunkParts(): Uint8Array[]; /** * Splits the chunk array at `pos` bytes from the start. * * Returns `before` (chunks whose content precedes `pos`) and `after` * (chunks from `pos` onward). The chunk that straddles `pos` is split into * two sub-arrays; either sub-array may be empty if the split falls exactly * at a chunk boundary. * * @param pos - Byte offset at which to split. */ private _splitAt; /** * Skips the first `n` bytes from `chunks`, returning the remaining content * as a new array of sub-array views. * * @param chunks - Source chunk array (not mutated). * @param n - Number of bytes to skip from the front. */ private _skipBytes; /** * Concatenates an array of `Uint8Array` chunks into a single contiguous * `Uint8Array`. * * @param chunks - Chunks to concatenate. */ private _concat; } //# sourceMappingURL=chunkedByteVectorStream.d.ts.map