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

188 lines
5.4 KiB
JavaScript

// Metro module 12721 (f12722).
import { assign, Buf8, arraySet, shrinkBuf, flattenChunks } from "./Module12712";
import * as _ZStream from "./ZStream";
import * as _InflateState from "./InflateState";
import { inflateInit2, inflateGetHeader, inflateSetDictionary, inflateEnd } from "./InflateState";
import { Z_OK, Z_FINISH, Z_NO_FLUSH, Z_NEED_DICT, Z_BUF_ERROR, Z_STREAM_END, Z_SYNC_FLUSH } from "./Module12725";
import * as _Module12716 from "./Module12716";
import * as _GZheader from "./GZheader";
import { binstring2buf, string2buf, utf8border, buf2string } from "./Module12720";
let toString;
const Inflate = function Inflate(a0) {
if (this instanceof Inflate) {
this.options = assign({
chunkSize: 16384,
windowBits: 0,
to: ""
}, a0 ? a0 : {});
const options = this.options;
if (options.raw && options.windowBits >= 0 && options.windowBits < 16) {
options.windowBits = -options.windowBits;
if (options.windowBits === 0) {
options.windowBits = -15;
}
}
const r3 = options.windowBits >= 0 && options.windowBits < 16;
if (!(r3 ? a0 ? a0.windowBits : a0 : !r3)) {
options.windowBits = options.windowBits + 32;
}
if (options.windowBits > 15 && options.windowBits < 48 && !(15 & options.windowBits)) {
options.windowBits = options.windowBits | 15;
}
this.err = 0;
this.msg = "";
this.ended = false;
this.chunks = [];
this.strm = new _ZStream();
this.strm.avail_out = 0;
const r66 = inflateInit2(this.strm, options.windowBits);
if (r66 !== Z_OK) {
throw new Error(_Module12716[r66]);
}
this.header = new _GZheader();
inflateGetHeader(this.strm, this.header);
return void 0;
}
const r17 = {
__proto__: Inflate.prototype
};
const r18 = Inflate.call(r17, a0);
return r18 instanceof Object ? r18 : r17;
};
export function inflate(a0, a1) {
const r2 = {
__proto__: Inflate.prototype
};
const r6 = Inflate.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;
}
toString = Object.prototype.toString;
Inflate.prototype.push = function(a0, a1) {
let r25, r177;
const strm = this.strm;
const chunkSize = this.options.chunkSize;
const dictionary = this.options.dictionary;
if (this.ended) {
return false;
}
let r16 = a1 !== ~~a1 ? a1 === true ? Z_FINISH : Z_NO_FLUSH : a1;
if (typeof a0 === "string") {
strm.input = binstring2buf(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 r6 = false;
while (true) {
const avail_out = strm.avail_out;
let r2 = r6;
if (avail_out === 0) {
strm.output = new Buf8(chunkSize);
strm.next_out = 0;
strm.avail_out = chunkSize;
}
let r86 = _InflateState.inflate(strm, Z_NO_FLUSH);
if (r86 === Z_NEED_DICT && dictionary) {
if (typeof dictionary === "string") {
r25 = string2buf(dictionary);
} else {
const call2 = toString.call;
r25 = toString.call(dictionary) === "[object ArrayBuffer]" ? new Uint8Array(dictionary) : dictionary;
}
r86 = inflateSetDictionary(this.strm, r25);
}
if (r86 === Z_BUF_ERROR && r2 === true) {
r86 = Z_OK;
r2 = false;
}
if (r86 !== Z_STREAM_END && r86 !== Z_OK) {
this.onEnd(r86);
this.ended = true;
return false;
}
if (strm.next_out && !(strm.avail_out !== 0 && r86 !== Z_STREAM_END && (strm.avail_in !== 0 || r16 !== Z_FINISH && r16 !== Z_SYNC_FLUSH))) {
if (this.options.to === "string") {
const r28 = utf8border(strm.output, strm.next_out);
const next_out = strm.next_out - r28;
const r148 = buf2string(strm.output, r28);
strm.next_out = next_out;
strm.avail_out = chunkSize - next_out;
if (next_out) {
arraySet(strm.output, strm.output, r28, next_out, 0);
}
this.onData(r148);
} else {
this.onData(shrinkBuf(strm.output, strm.next_out));
}
}
if (strm.avail_in === 0 && strm.avail_out === 0) {
r2 = true;
}
if (!(!(strm.avail_in > 0) && strm.avail_out !== 0)) {
r6 = r2;
if (r86 !== Z_STREAM_END) {
continue;
}
}
if (r86 === Z_STREAM_END) {
r16 = Z_FINISH;
}
if (r16 === Z_FINISH) {
const r187 = inflateEnd(this.strm);
this.onEnd(r187);
this.ended = true;
r177 = r187 === Z_OK;
} else {
r177 = r16 !== Z_SYNC_FLUSH;
if (!r177) {
this.onEnd(Z_OK);
strm.avail_out = 0;
r177 = true;
}
}
return r177;
}
};
Inflate.prototype.onData = function(a0) {
this.chunks.push(a0);
};
Inflate.prototype.onEnd = function(a0) {
if (a0 === Z_OK) {
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 { Inflate };
export function inflateRaw(a0, a1) {
const r5 = a1 ? a1 : {};
r5.raw = true;
const r6 = {
__proto__: Inflate.prototype
};
const r7 = Inflate.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 { inflate as ungzip };