Build 589089stable
Module 733344
2,148 characters · in 29609.b896f2d9d6398168.jsDependencies
Source Raw
function(e,t,n){"use strict";var r=n(683402),o=n(549412),i=n(382811),a=n(163173),u=n(267795),s=Object.prototype.toString;function l(e){if(!(this instanceof l))return new l(e);this.options=o.assign({level:-1,method:8,chunkSize:16384,windowBits:15,memLevel:8,strategy:0,to:""},e||{});var t,n=this.options;n.raw&&n.windowBits>0?n.windowBits=-n.windowBits:n.gzip&&n.windowBits>0&&n.windowBits<16&&(n.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new u,this.strm.avail_out=0;var c=r.deflateInit2(this.strm,n.level,n.method,n.windowBits,n.memLevel,n.strategy);if(0!==c)throw Error(a[c]);if(n.header&&r.deflateSetHeader(this.strm,n.header),n.dictionary){if(t="string"==typeof n.dictionary?i.string2buf(n.dictionary):"[object ArrayBuffer]"===s.call(n.dictionary)?new Uint8Array(n.dictionary):n.dictionary,0!==(c=r.deflateSetDictionary(this.strm,t)))throw Error(a[c]);this._dict_set=!0}}function c(e,t){var n=new l(t);if(n.push(e,!0),n.err)throw n.msg||a[n.err];return n.result}l.prototype.push=function(e,t){var n,a,u=this.strm,l=this.options.chunkSize;if(this.ended)return!1;a=t===~~t?t:4*(!0===t),"string"==typeof e?u.input=i.string2buf(e):"[object ArrayBuffer]"===s.call(e)?u.input=new Uint8Array(e):u.input=e,u.next_in=0,u.avail_in=u.input.length;do{if(0===u.avail_out&&(u.output=new o.Buf8(l),u.next_out=0,u.avail_out=l),1!==(n=r.deflate(u,a))&&0!==n)return this.onEnd(n),this.ended=!0,!1;(0===u.avail_out||0===u.avail_in&&(4===a||2===a))&&("string"===this.options.to?this.onData(i.buf2binstring(o.shrinkBuf(u.output,u.next_out))):this.onData(o.shrinkBuf(u.output,u.next_out)))}while((u.avail_in>0||0===u.avail_out)&&1!==n);return 4===a?(n=r.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,0===n):(2===a&&(this.onEnd(0),u.avail_out=0),!0)},l.prototype.onData=function(e){this.chunks.push(e)},l.prototype.onEnd=function(e){0===e&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=o.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg},t.Deflate=l,t.deflate=c,t.deflateRaw=function(e,t){return(t=t||{}).raw=!0,c(e,t)},t.gzip=function(e,t){return(t=t||{}).gzip=!0,c(e,t)}}