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.
25 lines (24 loc) • 670 B
JavaScript
import stream from 'node:stream';
import { crc32 } from '@node-rs/crc32';
/**
* A stream transform to calculate the size and CRC32 of a pre-compression file.
*/
export default class UncompressedTransform extends stream.Transform {
size = 0;
crc32;
/**
* Increment the size and update the CRC32, then passthrough the data.
*/
_transform(chunk, _encoding, callback) {
this.size += chunk.length;
this.crc32 = crc32(chunk, this.crc32);
// eslint-disable-next-line unicorn/no-null
callback(null, chunk);
}
getSize() {
return this.size;
}
getCrc32() {
return this.crc32 ?? 0;
}
}