@obarlik/streaming-pipeline-core
Version:
🔄 Memory-efficient circular buffer streaming pipeline with universal processing - by Codechu
97 lines (96 loc) • 2.39 kB
TypeScript
/**
* Memory-efficient circular buffer for streaming with bounded lookahead/lookbehind
*/
import { StreamPosition } from './streaming-interfaces';
export interface BufferState {
readonly size: number;
readonly position: number;
readonly available: number;
readonly canLookBehind: number;
readonly canLookAhead: number;
readonly isEOF: boolean;
readonly globalPosition: number;
}
export declare class CircularStreamBuffer {
private maxLookBehind;
private maxLookAhead;
private encoding;
private buffer;
private head;
private tail;
private current;
private globalPos;
private eof;
private filled;
constructor(maxLookBehind?: number, maxLookAhead?: number, encoding?: string);
/**
* Get current byte/character at processing position
*/
peek(): number | null;
/**
* Look behind up to maxLookBehind distance
*/
lookBehind(distance: number): Uint8Array;
/**
* Look ahead up to maxLookAhead distance
*/
lookAhead(distance: number): Uint8Array;
/**
* Advance processing position by one
*/
advance(): boolean;
/**
* Check if we can advance
*/
canAdvance(): boolean;
/**
* Fill buffer with new streaming data
*/
fill(data: Uint8Array): void;
/**
* Mark end of stream
*/
markEOF(): void;
/**
* Get buffer state information
*/
getState(): BufferState;
/**
* Get current position in stream coordinates
*/
getStreamPosition(): StreamPosition;
/**
* Check if buffer needs more data
*/
needsRefill(): boolean;
/**
* Clear buffer and reset
*/
reset(): void;
private getAvailableBehind;
private getAvailableAhead;
private autoCompact;
}
/**
* String-aware circular buffer for text processing
*/
export declare class TextCircularBuffer extends CircularStreamBuffer {
private decoder;
constructor(maxLookBehind?: number, maxLookAhead?: number, encoding?: string);
/**
* Get current character as string
*/
peekChar(): string | null;
/**
* Look behind as string
*/
lookBehindString(distance: number): string;
/**
* Look ahead as string
*/
lookAheadString(distance: number): string;
/**
* Fill with string data
*/
fillString(text: string): void;
}