Initial commit

This commit is contained in:
jiapengyu
2026-07-27 13:37:48 +08:00
commit ecba71e2a5
39123 changed files with 5989154 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { Transform } from "readable-stream";
import crc32 from "crc-32";
export default class CRC32Stream extends Transform {
constructor(options) {
super(options);
this.checksum = Buffer.allocUnsafe(4);
this.checksum.writeInt32BE(0, 0);
this.rawSize = 0;
}
_transform(chunk, encoding, callback) {
if (chunk) {
this.checksum = crc32.buf(chunk, this.checksum) >>> 0;
this.rawSize += chunk.length;
}
callback(null, chunk);
}
digest(encoding) {
const checksum = Buffer.allocUnsafe(4);
checksum.writeUInt32BE(this.checksum >>> 0, 0);
return encoding ? checksum.toString(encoding) : checksum;
}
hex() {
return this.digest("hex").toUpperCase();
}
size() {
return this.rawSize;
}
}
+40
View File
@@ -0,0 +1,40 @@
import { DeflateRaw } from "zlib";
import crc32 from "crc-32";
export default class DeflateCRC32Stream extends DeflateRaw {
constructor(options) {
super(options);
this.checksum = Buffer.allocUnsafe(4);
this.checksum.writeInt32BE(0, 0);
this.rawSize = 0;
this.compressedSize = 0;
}
push(chunk, encoding) {
if (chunk) {
this.compressedSize += chunk.length;
}
return super.push(chunk, encoding);
}
_transform(chunk, encoding, callback) {
if (chunk) {
this.checksum = crc32.buf(chunk, this.checksum) >>> 0;
this.rawSize += chunk.length;
}
super._transform(chunk, encoding, callback);
}
digest(encoding) {
const checksum = Buffer.allocUnsafe(4);
checksum.writeUInt32BE(this.checksum >>> 0, 0);
return encoding ? checksum.toString(encoding) : checksum;
}
hex() {
return this.digest("hex").toUpperCase();
}
size(compressed = false) {
if (compressed) {
return this.compressedSize;
} else {
return this.rawSize;
}
}
}
+15
View File
@@ -0,0 +1,15 @@
/**
* node-crc32-stream
*
* Copyright (c) 2014 Chris Talkington, contributors.
* Licensed under the MIT license.
* https://github.com/archiverjs/node-crc32-stream/blob/master/LICENSE-MIT
*/
import CRC32Stream from "./crc32-stream.js";
import DeflateCRC32Stream from "./deflate-crc32-stream.js";
export { CRC32Stream, DeflateCRC32Stream };
export default {
CRC32Stream,
DeflateCRC32Stream,
};