extract-base-iterator
Version:
Base iterator for extract iterators like tar-iterator and zip-iterator
77 lines (76 loc) • 2.24 kB
text/typescript
/**
* Buffer List for Streaming
*
* Simple linked list for accumulating buffer chunks during streaming.
* Provides efficient append, consume, and slice operations.
*/
export default class BufferList {
private head;
private tail;
/** Total bytes in the buffer list */
length: number;
/**
* Append a buffer to the end of the list
*/
append(buf: Buffer): void;
/**
* Prepend a buffer to the front of the list
*/
prepend(buf: Buffer): void;
/**
* Consume n bytes from the front of the list
* Returns a new buffer containing the consumed bytes
*/
consume(n: number): Buffer;
/**
* Get a slice of the buffer without consuming
* Returns a new buffer containing the bytes
*/
slice(start: number, end: number): Buffer;
/**
* Read a single byte at offset without consuming
*/
readByte(offset: number): number;
/**
* Search for a byte sequence in the buffer
* Returns offset of first match, or -1 if not found
*/
indexOf(signature: number[], startOffset?: number): number;
/**
* Skip (consume) n bytes without returning them
*/
skip(n: number): void;
/**
* Clear all buffers
*/
clear(): void;
/**
* Check if buffer has at least n bytes available
*/
has(n: number): boolean;
/**
* Check if the buffer starts with a signature at offset 0
*/
startsWith(signature: number[]): boolean;
/**
* Get a consolidated buffer of the entire contents
* Note: This creates a copy, so use sparingly for large buffers
*/
toBuffer(): Buffer;
/**
* Read UInt16 (little-endian) at offset without consuming
* Returns null if not enough data
*/
readUInt16LEAt(offset: number): number | null;
/**
* Read UInt32 (little-endian) at offset without consuming
* Returns null if not enough data
*/
readUInt32LEAt(offset: number): number | null;
/**
* Read bytes at offset without consuming.
* Returns a slice (zero-copy) when data fits within a single chunk,
* otherwise allocates and copies from multiple chunks.
*/
readBytesAt(offset: number, length: number): Buffer;
}