@mountainpass/hooked-cli
Version:
A tool for runnable scripts
23 lines (22 loc) • 592 B
JavaScript
import { Transform } from "stream";
export class CaptureTransformStream extends Transform {
constructor(originalStream, options) {
super(options);
this.captureBuffer = '';
this.finished = false;
this.originalStream = originalStream;
}
_transform(chunk, encoding, callback) {
// Capture the data
this.captureBuffer += chunk.toString();
// Pass the data through
this.push(chunk);
callback();
}
_flush(callback) {
callback();
}
getCaptured() {
return this.captureBuffer;
}
}