Files
NapCatQQ/.pnpm-store/v3/files/2b/a1c9cd8a2d10c1552f38057aa594944453c1f36b1263fb667a69916057a8016fde9d9f50f52ad74888873e8ed2aa3bca672f775ba3c1f1211a00d5a8144dd6
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

54 lines
1.8 KiB
Plaintext

import { AsyncGunzip } from 'fflate';
export class GzipHandler {
constructor(tokenizer) {
this.gunzip = undefined;
this.tokenizer = tokenizer;
}
inflate() {
let done = false;
let cancelled = false;
const parent = this;
return new ReadableStream({
start: controller => {
parent.gunzip = new AsyncGunzip((err, chunk, final) => {
if (err) {
controller.error(err);
return;
}
if (chunk && !cancelled) {
controller.enqueue(chunk);
}
if (final && !cancelled) {
controller.close();
parent.gunzip.terminate();
}
});
},
async pull(controller) {
const chunkSize = 1024;
try {
const buffer = new Uint8Array(chunkSize);
const size = await parent.tokenizer.readBuffer(buffer, { mayBeLess: true });
if (size === 0) {
if (!done) {
done = true;
if (!cancelled) {
parent.gunzip.push(new Uint8Array(0), true);
}
}
return;
}
parent.gunzip.push(buffer.subarray(0, size), false);
}
catch (err) {
controller.error(err);
}
},
cancel: () => {
parent.gunzip.terminate();
cancelled = true;
}
});
}
}