smartstream/ts/smartstream.classes.passthrough.ts

19 lines
512 B
TypeScript
Raw Normal View History

2023-11-01 23:30:15 +00:00
import * as plugins from './smartstream.plugins.js';
export class PassThrough extends plugins.stream.Duplex {
constructor(options?: plugins.stream.DuplexOptions) {
super(options);
}
_read(size: number): void {
// No-op: Data written will be automatically available for reading.
}
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
if (this.push(chunk, encoding)) {
callback();
} else {
this.once('drain', callback);
}
}
}