UNPKG

@xec-sh/core

Version:

Universal shell execution engine

81 lines (80 loc) 3.24 kB
import { EventEmitter } from 'node:events'; import { Readable, Writable, Transform } from 'node:stream'; import type { Command } from '../core/command.js'; import type { ExecutionEngine } from '../core/execution-engine.js'; export interface StreamHandlerOptions { encoding?: BufferEncoding; maxBuffer?: number; onData?: (chunk: string) => void; onError?: (error: Error) => void; } export declare class StreamHandler { private buffer; private totalLength; private decoder; private readonly encoding; private readonly maxBuffer; private readonly onData?; private readonly onError?; constructor(options?: StreamHandlerOptions); createTransform(): Transform; getContent(): string; getBuffer(): Buffer; reset(): void; } export declare function createLineTransform(onLine: (line: string) => void): Transform; export declare class LineTransform extends Transform { private transform; private encoding; private buffer; constructor(transform: (line: string) => string | null, encoding?: BufferEncoding); _transform(chunk: Buffer, encoding: string, callback: Function): void; _flush(callback: Function): void; } export declare function streamToString(stream: Readable, encoding?: BufferEncoding): Promise<string>; export declare const collectStream: typeof streamToString; export declare function combineStreams(stdout: Readable, stderr: Readable): Readable; export interface StreamOptions { encoding?: BufferEncoding; lineMode?: boolean; bufferSize?: number; } export declare class StreamingExecution extends EventEmitter { private engine; private command; private options; private stdout; private stderr; private process; constructor(engine: ExecutionEngine, command: Command, options?: StreamOptions); start(): Promise<void>; private setupLineMode; getStdout(): Readable; getStderr(): Readable; lines(): AsyncIterableIterator<{ line: string; stream: 'stdout' | 'stderr'; }>; pipe(destination: Writable | Transform): StreamingExecution; wait(): Promise<number>; kill(signal?: NodeJS.Signals): void; } export declare function stream(engine: ExecutionEngine, command: string | Command, options?: StreamOptions): StreamingExecution; export declare class StreamCollector extends Transform { private maxSize?; private chunks; constructor(maxSize?: number | undefined); _transform(chunk: Buffer, encoding: string, callback: Function): void; getBuffer(): Buffer; getText(encoding?: BufferEncoding): string; } export declare class ProgressTracker extends Transform { private onProgress; private totalBytes; private startTime; constructor(onProgress: (bytes: number, totalBytes: number, bytesPerSecond: number) => void); _transform(chunk: Buffer, encoding: string, callback: Function): void; } export declare function createOutputStream(option: string | Writable | ((chunk: string) => void), isStderr?: boolean): Writable; export declare function createInputStream(input: string | Buffer | Readable | null | undefined): Readable | null | undefined; export declare function pipeStreams(source: Readable, destination: Writable): void;