[JavaScript] 纯文本查看 复制代码
,function(t, e, n) {
"use strict";
var r = n(277)
, i = n(515)
, o = n(218)
, a = n(248)
, s = n(419)
, u = Object.prototype.toString
, l = 0
, c = 1
, f = 10
, d = 6;
function h(t) {
if (!(this instanceof h))
return new h(t);
this.options = i.assign({
level: c,
method: d,
chunkSize: 16384,
windowBits: 15,
memLevel: 8,
strategy: f,
to: ""
}, t || {});
var e = this.options;
e.raw && 0 < e.windowBits ? e.windowBits = -e.windowBits : e.gzip && 0 < e.windowBits && e.windowBits < 16 && (e.windowBits += 16),
this.err = 0,
this.msg = "",
this.ended = !1,
this.chunks = [],
this.strm = new s,
this.strm.avail_out = 0;
var n = r.deflateInit2(this.strm, e.level, e.method, e.windowBits, e.memLevel, e.strategy);
if (n !== l)
throw new Error(a[n]);
if (e.header && r.deflateSetHeader(this.strm, e.header),
e.dictionary) {
var p;
if (p = "string" == typeof e.dictionary ? o.string2buf(e.dictionary) : "[object ArrayBuffer]" === u.call(e.dictionary) ? new Uint8Array(e.dictionary) : e.dictionary,
(n = r.deflateSetDictionary(this.strm, p)) !== l)
throw new Error(a[n]);
this._dict_set = !0
}
}
function p(t, e) {
var n = new h(e);
if (n.push(t, !0),
n.err)
throw n.msg || a[n.err];
return n.result
}
h.prototype.push = function(t, e) {
var n, a, s = this.strm, c = this.options.chunkSize;
if (this.ended)
return !1;
a = e === ~~e ? e : !0 === e ? 4 : 0,
"string" == typeof t ? s.input = o.string2buf(t) : "[object ArrayBuffer]" === u.call(t) ? s.input = new Uint8Array(t) : s.input = t,
s.next_in = 0,
s.avail_in = s.input.length;
do {
if (0 === s.avail_out && (s.output = new i.Buf8(c),
s.next_out = 0,
s.avail_out = c),
1 !== (n = r.deflate(s, a)) && n !== l)
return this.onEnd(n),
!(this.ended = !0);
0 !== s.avail_out && (0 !== s.avail_in || 4 !== a && 2 !== a) || ("string" === this.options.to ? this.onData(o.buf2binstring(i.shrinkBuf(s.output, s.next_out))) : this.onData(i.shrinkBuf(s.output, s.next_out)))
} while ((0 < s.avail_in || 0 === s.avail_out) && 1 !== n);return 4 === a ? (n = r.deflateEnd(this.strm),
this.onEnd(n),
this.ended = !0,
n === l) : 2 !== a || (this.onEnd(l),
!(s.avail_out = 0))
}
,
h.prototype.onData = function(t) {
this.chunks.push(t)
}
,
h.prototype.onEnd = function(t) {
t === l && ("string" === this.options.to ? this.result = this.chunks.join("") : this.result = i.flattenChunks(this.chunks)),
this.chunks = [],
this.err = t,
this.msg = this.strm.msg
}
,
e.Deflate = h,
e.deflate = p,
e.deflateRaw = function(t, e) {
return (e = e || {}).raw = !0,
p(t, e)
}
,
e.gzip = function(t, e) {
return (e = e || {}).gzip = !0,
p(t, e)
}
},