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