@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
22 lines (21 loc) • 591 B
JavaScript
import { Transform } from 'node:stream';
import { progressLogger } from '../progressLogger.js';
/**
* Pass-through transform that optionally logs progress.
*/
export function transformLogProgress(opt = {}) {
const { objectMode = true, highWaterMark = 1 } = opt;
const progress = progressLogger(opt);
return new Transform({
objectMode,
highWaterMark,
transform(chunk, _, cb) {
progress.log(chunk);
cb(null, chunk); // pass-through
},
final(cb) {
progress.done();
cb();
},
});
}