igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
24 lines (23 loc) • 660 B
JavaScript
import stream from 'node:stream';
/**
* A stream transformer that tracks how many bytes have been read and calls a callback.
*/
export default class ProgressTransform extends stream.Transform {
progressCallback;
progress = 0;
constructor(progressCallback) {
super();
this.progressCallback = progressCallback;
}
/**
* Process the stream.
*/
_transform(chunk, _encoding, callback) {
this.progress += chunk.length;
if (this.progressCallback) {
this.progressCallback(this.progress);
}
// eslint-disable-next-line unicorn/no-null
callback(null, chunk);
}
}