smartstream/ts/smartstream.classes.passthrough.ts

21 lines
539 B
TypeScript
Raw Permalink 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 {
2023-11-03 23:17:03 +00:00
this.once('drain', () => {
callback();
});
2023-11-01 23:30:15 +00:00
}
}
}