Files
discord-decomp/_bundle/Deflate.js
T
2026-11-01 12:12:55 +02:00

175 lines
4.7 KiB
JavaScript

// Metro module 12713 (f12714).
import { assign, Buf8, shrinkBuf, flattenChunks } from "./Module12712";
import * as _ZStream from "./ZStream";
import * as _flush_block_only from "./flush_block_only";
import { deflateInit2, deflateSetHeader, deflateSetDictionary, deflateEnd } from "./flush_block_only";
import * as _Module12716 from "./Module12716";
import { string2buf, buf2binstring } from "./Module12720";
let toString;
const Deflate = function Deflate(a0) {
let r69;
if (this instanceof Deflate) {
this.options = assign({
level: -1,
method: 8,
chunkSize: 16384,
windowBits: 15,
memLevel: 8,
strategy: 0,
to: ""
}, a0 ? a0 : {});
const options = this.options;
if (options.raw && options.windowBits > 0) {
options.windowBits = -options.windowBits;
} else if (options.gzip && options.windowBits > 0 && options.windowBits < 16) {
options.windowBits = options.windowBits + 16;
}
this.err = 0;
this.msg = "";
this.ended = false;
this.chunks = [];
this.strm = new _ZStream();
this.strm.avail_out = 0;
const r56 = deflateInit2(this.strm, options.level, options.method, options.windowBits, options.memLevel, options.strategy);
if (r56 !== 0) {
throw new Error(_Module12716[r56]);
}
if (options.header) {
deflateSetHeader(this.strm, options.header);
}
if (options.dictionary) {
if (typeof options.dictionary === "string") {
r69 = string2buf(options.dictionary);
} else {
const call = toString.call;
r69 = toString.call(options.dictionary) === "[object ArrayBuffer]" ? new Uint8Array(options.dictionary) : options.dictionary;
}
const r84 = deflateSetDictionary(this.strm, r69);
if (r84 !== 0) {
throw new Error(_Module12716[r84]);
}
this._dict_set = true;
}
return void 0;
}
const r23 = {
__proto__: Deflate.prototype
};
const r24 = Deflate.call(r23, a0);
return r24 instanceof Object ? r24 : r23;
};
toString = Object.prototype.toString;
Deflate.prototype.push = function(a0, a1) {
const strm = this.strm;
const chunkSize = this.options.chunkSize;
if (this.ended) {
return false;
}
const r15 = a1 !== ~~a1 ? a1 === true ? 4 : 0 : a1;
if (typeof a0 === "string") {
strm.input = string2buf(a0);
} else {
const call = toString.call;
if (toString.call(a0) === "[object ArrayBuffer]") {
strm.input = new Uint8Array(a0);
} else {
strm.input = a0;
}
}
strm.next_in = 0;
strm.avail_in = strm.input.length;
let r51 = r15 !== 2;
const r8 = r15 !== 4;
while (true) {
if (strm.avail_out === 0) {
strm.output = new Buf8(chunkSize);
strm.next_out = 0;
strm.avail_out = chunkSize;
}
const r68 = _flush_block_only.deflate(strm, r15);
const r9 = r68 !== 1;
if (r9 && r68 !== 0) {
this.onEnd(r68);
this.ended = true;
return false;
}
if (!(strm.avail_out !== 0 && (strm.avail_in !== 0 || r8 && r51))) {
if (this.options.to === "string") {
this.onData(buf2binstring(shrinkBuf(strm.output, strm.next_out)));
} else {
this.onData(shrinkBuf(strm.output, strm.next_out));
}
}
if (!(!(strm.avail_in > 0) && strm.avail_out !== 0) && r9) {
continue;
}
if (r15 === 4) {
const r95 = deflateEnd(this.strm);
this.onEnd(r95);
this.ended = true;
r51 = r95 === 0;
} else if (!r51) {
this.onEnd(0);
strm.avail_out = 0;
r51 = true;
}
return r51;
}
};
Deflate.prototype.onData = function(a0) {
this.chunks.push(a0);
};
Deflate.prototype.onEnd = function(a0) {
if (a0 === 0) {
if (this.options.to === "string") {
this.result = this.chunks.join("");
} else {
this.result = flattenChunks(this.chunks);
}
}
this.chunks = [];
this.err = a0;
this.msg = this.strm.msg;
};
export { Deflate };
export function deflate(a0, a1) {
const r2 = {
__proto__: Deflate.prototype
};
const r6 = Deflate.call(r2, a1);
const r7 = r6 instanceof Object ? r6 : r2;
r7.push(a0, true);
if (r7.err) {
throw r7.msg || _Module12716[r7.err];
}
return r7.result;
}
export function deflateRaw(a0, a1) {
const r5 = a1 ? a1 : {};
r5.raw = true;
const r6 = {
__proto__: Deflate.prototype
};
const r7 = Deflate.call(r6, r5);
const r8 = r7 instanceof Object ? r7 : r6;
r8.push(a0, true);
if (r8.err) {
throw r8.msg || _Module12716[r8.err];
}
return r8.result;
}
export function gzip(a0, a1) {
const r5 = a1 ? a1 : {};
r5.gzip = true;
const r6 = {
__proto__: Deflate.prototype
};
const r7 = Deflate.call(r6, r5);
const r8 = r7 instanceof Object ? r7 : r6;
r8.push(a0, true);
if (r8.err) {
throw r8.msg || _Module12716[r8.err];
}
return r8.result;
}