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.
22 lines (21 loc) • 597 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 FsReadTransform extends stream.Transform {
fsReadCallback;
progress = 0;
constructor(fsReadCallback) {
super();
this.fsReadCallback = fsReadCallback;
}
/**
* Process the stream.
*/
_transform(chunk, _encoding, callback) {
this.progress += chunk.length;
this.fsReadCallback(this.progress);
// eslint-disable-next-line unicorn/no-null
callback(null, chunk);
}
}