@obarlik/streaming-pipeline-core
Version:
🔄 Memory-efficient circular buffer streaming pipeline with universal processing - by Codechu
62 lines (61 loc) • 1.96 kB
JavaScript
import { StreamingPipeline, PipelineFactory } from '../orchestrator/StreamingPipeline';
/**
* 🌊 Fluent API for streaming pipeline configuration
* Chain methods for easy setup: pipeline().buffer().processor().render()
*/
export class FluentPipeline {
constructor(pipeline) {
this.pipeline = pipeline || new StreamingPipeline();
}
/** 📦 Configure circular buffer sizes */
buffer(options) {
const fullOptions = {
lookBehindSize: 512,
lookAheadSize: 2048,
encoding: 'utf-8',
autoCompact: true,
...options
};
this.pipeline.configureBuffer(fullOptions);
return this;
}
/** ⚡ Add stream processor */
processor(processor) {
this.pipeline.registerProcessor(processor);
return this;
}
/** 🎨 Add renderer for output format */
renderer(renderer) {
this.pipeline.registerRenderer(renderer);
return this;
}
/** 🔄 Process stream with configured pipeline */
async *stream(input, format) {
yield* this.pipeline.processStream(input, format);
}
/** 📋 Get configured pipeline instance */
build() {
return this.pipeline;
}
}
/**
* 🚀 Factory helpers for common configurations
*/
export class FluentFactory {
/** 📝 Text processing with reasonable defaults */
static text() {
return new FluentPipeline(PipelineFactory.createTextPipeline());
}
/** 📊 Binary processing optimized */
static binary() {
return new FluentPipeline(PipelineFactory.createBinaryPipeline());
}
/** ⚡ High-performance for large content */
static performance() {
return new FluentPipeline(PipelineFactory.createHighPerformancePipeline());
}
/** 💾 Memory-constrained environments */
static minimal() {
return new FluentPipeline().buffer({ lookBehindSize: 32, lookAheadSize: 64 });
}
}