├── .gitignore ├── HISTORY.md ├── LICENSE ├── README.md ├── demo.png ├── dist ├── photon.js └── photon.min.js ├── package.json ├── src ├── highlighter.js └── index.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | yarn-error.log 4 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | v0.1.3 / 2017-05-18 2 | =================== 3 | 4 | * Added error handling 5 | * Versions bump 6 | 7 | v0.1.2 / 2017-03-21 8 | =================== 9 | 10 | * Versions bump 11 | 12 | 13 | v0.1.1 / 2017-03-18 14 | =================== 15 | 16 | * Changed HTTP auth schema 17 | 18 | 19 | v0.1.0 / 2017-03-18 20 | =================== 21 | 22 | * Initial release 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Photon, https://photon.sh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # photon-js 2 | 3 | photon-js is a JavaScript library for [Photon](https://photon.sh). 4 | 5 | ![Photon](https://raw.githubusercontent.com/photonsh/photon-js/master/demo.png) 6 | 7 | *We have a lot of plugins but you do not have to use them all!* 8 | 9 | **Note**: If you are using JavaScript on the server, refer to the [photon-node](https://github.com/photonsh/photon-node) library. 10 | 11 | ## Resources 12 | 13 | * **[Website](https://photon.sh)** 14 | * **[Sign Up](https://photon.sh/signup)** 15 | * **[Demo](https://photon.sh/demo)** 16 | * **[Documentation](https://photon.sh/docs/libraries/javascript)** 17 | * **[Twitter](https://twitter.com/photondotsh)** 18 | 19 | ## License 20 | 21 | [MIT License](https://github.com/photonsh/photon-js/LICENSE) 22 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/photonsh/photon-js/8f69a19bfa9c96c4b5f6a25290bf35e6237e3efe/demo.png -------------------------------------------------------------------------------- /dist/photon.js: -------------------------------------------------------------------------------- 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.photon = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o Array 42 | * 43 | * Chunks of output data, if [[Deflate#onData]] not overriden. 44 | **/ 45 | 46 | /** 47 | * Deflate.result -> Uint8Array|Array 48 | * 49 | * Compressed result, generated by default [[Deflate#onData]] 50 | * and [[Deflate#onEnd]] handlers. Filled after you push last chunk 51 | * (call [[Deflate#push]] with `Z_FINISH` / `true` param) or if you 52 | * push a chunk with explicit flush (call [[Deflate#push]] with 53 | * `Z_SYNC_FLUSH` param). 54 | **/ 55 | 56 | /** 57 | * Deflate.err -> Number 58 | * 59 | * Error code after deflate finished. 0 (Z_OK) on success. 60 | * You will not need it in real life, because deflate errors 61 | * are possible only on wrong options or bad `onData` / `onEnd` 62 | * custom handlers. 63 | **/ 64 | 65 | /** 66 | * Deflate.msg -> String 67 | * 68 | * Error message, if [[Deflate.err]] != 0 69 | **/ 70 | 71 | 72 | /** 73 | * new Deflate(options) 74 | * - options (Object): zlib deflate options. 75 | * 76 | * Creates new deflator instance with specified params. Throws exception 77 | * on bad params. Supported options: 78 | * 79 | * - `level` 80 | * - `windowBits` 81 | * - `memLevel` 82 | * - `strategy` 83 | * - `dictionary` 84 | * 85 | * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) 86 | * for more information on these. 87 | * 88 | * Additional options, for internal needs: 89 | * 90 | * - `chunkSize` - size of generated data chunks (16K by default) 91 | * - `raw` (Boolean) - do raw deflate 92 | * - `gzip` (Boolean) - create gzip wrapper 93 | * - `to` (String) - if equal to 'string', then result will be "binary string" 94 | * (each char code [0..255]) 95 | * - `header` (Object) - custom header for gzip 96 | * - `text` (Boolean) - true if compressed data believed to be text 97 | * - `time` (Number) - modification time, unix timestamp 98 | * - `os` (Number) - operation system code 99 | * - `extra` (Array) - array of bytes with extra data (max 65536) 100 | * - `name` (String) - file name (binary string) 101 | * - `comment` (String) - comment (binary string) 102 | * - `hcrc` (Boolean) - true if header crc should be added 103 | * 104 | * ##### Example: 105 | * 106 | * ```javascript 107 | * var pako = require('pako') 108 | * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9]) 109 | * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]); 110 | * 111 | * var deflate = new pako.Deflate({ level: 3}); 112 | * 113 | * deflate.push(chunk1, false); 114 | * deflate.push(chunk2, true); // true -> last chunk 115 | * 116 | * if (deflate.err) { throw new Error(deflate.err); } 117 | * 118 | * console.log(deflate.result); 119 | * ``` 120 | **/ 121 | function Deflate(options) { 122 | if (!(this instanceof Deflate)) return new Deflate(options); 123 | 124 | this.options = utils.assign({ 125 | level: Z_DEFAULT_COMPRESSION, 126 | method: Z_DEFLATED, 127 | chunkSize: 16384, 128 | windowBits: 15, 129 | memLevel: 8, 130 | strategy: Z_DEFAULT_STRATEGY, 131 | to: '' 132 | }, options || {}); 133 | 134 | var opt = this.options; 135 | 136 | if (opt.raw && (opt.windowBits > 0)) { 137 | opt.windowBits = -opt.windowBits; 138 | } 139 | 140 | else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) { 141 | opt.windowBits += 16; 142 | } 143 | 144 | this.err = 0; // error code, if happens (0 = Z_OK) 145 | this.msg = ''; // error message 146 | this.ended = false; // used to avoid multiple onEnd() calls 147 | this.chunks = []; // chunks of compressed data 148 | 149 | this.strm = new ZStream(); 150 | this.strm.avail_out = 0; 151 | 152 | var status = zlib_deflate.deflateInit2( 153 | this.strm, 154 | opt.level, 155 | opt.method, 156 | opt.windowBits, 157 | opt.memLevel, 158 | opt.strategy 159 | ); 160 | 161 | if (status !== Z_OK) { 162 | throw new Error(msg[status]); 163 | } 164 | 165 | if (opt.header) { 166 | zlib_deflate.deflateSetHeader(this.strm, opt.header); 167 | } 168 | 169 | if (opt.dictionary) { 170 | var dict; 171 | // Convert data if needed 172 | if (typeof opt.dictionary === 'string') { 173 | // If we need to compress text, change encoding to utf8. 174 | dict = strings.string2buf(opt.dictionary); 175 | } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') { 176 | dict = new Uint8Array(opt.dictionary); 177 | } else { 178 | dict = opt.dictionary; 179 | } 180 | 181 | status = zlib_deflate.deflateSetDictionary(this.strm, dict); 182 | 183 | if (status !== Z_OK) { 184 | throw new Error(msg[status]); 185 | } 186 | 187 | this._dict_set = true; 188 | } 189 | } 190 | 191 | /** 192 | * Deflate#push(data[, mode]) -> Boolean 193 | * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be 194 | * converted to utf8 byte sequence. 195 | * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes. 196 | * See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH. 197 | * 198 | * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with 199 | * new compressed chunks. Returns `true` on success. The last data block must have 200 | * mode Z_FINISH (or `true`). That will flush internal pending buffers and call 201 | * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you 202 | * can use mode Z_SYNC_FLUSH, keeping the compression context. 203 | * 204 | * On fail call [[Deflate#onEnd]] with error code and return false. 205 | * 206 | * We strongly recommend to use `Uint8Array` on input for best speed (output 207 | * array format is detected automatically). Also, don't skip last param and always 208 | * use the same type in your code (boolean or number). That will improve JS speed. 209 | * 210 | * For regular `Array`-s make sure all elements are [0..255]. 211 | * 212 | * ##### Example 213 | * 214 | * ```javascript 215 | * push(chunk, false); // push one of data chunks 216 | * ... 217 | * push(chunk, true); // push last chunk 218 | * ``` 219 | **/ 220 | Deflate.prototype.push = function (data, mode) { 221 | var strm = this.strm; 222 | var chunkSize = this.options.chunkSize; 223 | var status, _mode; 224 | 225 | if (this.ended) { return false; } 226 | 227 | _mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH); 228 | 229 | // Convert data if needed 230 | if (typeof data === 'string') { 231 | // If we need to compress text, change encoding to utf8. 232 | strm.input = strings.string2buf(data); 233 | } else if (toString.call(data) === '[object ArrayBuffer]') { 234 | strm.input = new Uint8Array(data); 235 | } else { 236 | strm.input = data; 237 | } 238 | 239 | strm.next_in = 0; 240 | strm.avail_in = strm.input.length; 241 | 242 | do { 243 | if (strm.avail_out === 0) { 244 | strm.output = new utils.Buf8(chunkSize); 245 | strm.next_out = 0; 246 | strm.avail_out = chunkSize; 247 | } 248 | status = zlib_deflate.deflate(strm, _mode); /* no bad return value */ 249 | 250 | if (status !== Z_STREAM_END && status !== Z_OK) { 251 | this.onEnd(status); 252 | this.ended = true; 253 | return false; 254 | } 255 | if (strm.avail_out === 0 || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) { 256 | if (this.options.to === 'string') { 257 | this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out))); 258 | } else { 259 | this.onData(utils.shrinkBuf(strm.output, strm.next_out)); 260 | } 261 | } 262 | } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END); 263 | 264 | // Finalize on the last chunk. 265 | if (_mode === Z_FINISH) { 266 | status = zlib_deflate.deflateEnd(this.strm); 267 | this.onEnd(status); 268 | this.ended = true; 269 | return status === Z_OK; 270 | } 271 | 272 | // callback interim results if Z_SYNC_FLUSH. 273 | if (_mode === Z_SYNC_FLUSH) { 274 | this.onEnd(Z_OK); 275 | strm.avail_out = 0; 276 | return true; 277 | } 278 | 279 | return true; 280 | }; 281 | 282 | 283 | /** 284 | * Deflate#onData(chunk) -> Void 285 | * - chunk (Uint8Array|Array|String): ouput data. Type of array depends 286 | * on js engine support. When string output requested, each chunk 287 | * will be string. 288 | * 289 | * By default, stores data blocks in `chunks[]` property and glue 290 | * those in `onEnd`. Override this handler, if you need another behaviour. 291 | **/ 292 | Deflate.prototype.onData = function (chunk) { 293 | this.chunks.push(chunk); 294 | }; 295 | 296 | 297 | /** 298 | * Deflate#onEnd(status) -> Void 299 | * - status (Number): deflate status. 0 (Z_OK) on success, 300 | * other if not. 301 | * 302 | * Called once after you tell deflate that the input stream is 303 | * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH) 304 | * or if an error happened. By default - join collected chunks, 305 | * free memory and fill `results` / `err` properties. 306 | **/ 307 | Deflate.prototype.onEnd = function (status) { 308 | // On success - join 309 | if (status === Z_OK) { 310 | if (this.options.to === 'string') { 311 | this.result = this.chunks.join(''); 312 | } else { 313 | this.result = utils.flattenChunks(this.chunks); 314 | } 315 | } 316 | this.chunks = []; 317 | this.err = status; 318 | this.msg = this.strm.msg; 319 | }; 320 | 321 | 322 | /** 323 | * deflate(data[, options]) -> Uint8Array|Array|String 324 | * - data (Uint8Array|Array|String): input data to compress. 325 | * - options (Object): zlib deflate options. 326 | * 327 | * Compress `data` with deflate algorithm and `options`. 328 | * 329 | * Supported options are: 330 | * 331 | * - level 332 | * - windowBits 333 | * - memLevel 334 | * - strategy 335 | * - dictionary 336 | * 337 | * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) 338 | * for more information on these. 339 | * 340 | * Sugar (options): 341 | * 342 | * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify 343 | * negative windowBits implicitly. 344 | * - `to` (String) - if equal to 'string', then result will be "binary string" 345 | * (each char code [0..255]) 346 | * 347 | * ##### Example: 348 | * 349 | * ```javascript 350 | * var pako = require('pako') 351 | * , data = Uint8Array([1,2,3,4,5,6,7,8,9]); 352 | * 353 | * console.log(pako.deflate(data)); 354 | * ``` 355 | **/ 356 | function deflate(input, options) { 357 | var deflator = new Deflate(options); 358 | 359 | deflator.push(input, true); 360 | 361 | // That will never happens, if you don't cheat with options :) 362 | if (deflator.err) { throw deflator.msg || msg[deflator.err]; } 363 | 364 | return deflator.result; 365 | } 366 | 367 | 368 | /** 369 | * deflateRaw(data[, options]) -> Uint8Array|Array|String 370 | * - data (Uint8Array|Array|String): input data to compress. 371 | * - options (Object): zlib deflate options. 372 | * 373 | * The same as [[deflate]], but creates raw data, without wrapper 374 | * (header and adler32 crc). 375 | **/ 376 | function deflateRaw(input, options) { 377 | options = options || {}; 378 | options.raw = true; 379 | return deflate(input, options); 380 | } 381 | 382 | 383 | /** 384 | * gzip(data[, options]) -> Uint8Array|Array|String 385 | * - data (Uint8Array|Array|String): input data to compress. 386 | * - options (Object): zlib deflate options. 387 | * 388 | * The same as [[deflate]], but create gzip wrapper instead of 389 | * deflate one. 390 | **/ 391 | function gzip(input, options) { 392 | options = options || {}; 393 | options.gzip = true; 394 | return deflate(input, options); 395 | } 396 | 397 | 398 | exports.Deflate = Deflate; 399 | exports.deflate = deflate; 400 | exports.deflateRaw = deflateRaw; 401 | exports.gzip = gzip; 402 | 403 | },{"./utils/common":2,"./utils/strings":3,"./zlib/deflate":6,"./zlib/messages":7,"./zlib/zstream":9}],2:[function(require,module,exports){ 404 | 'use strict'; 405 | 406 | 407 | var TYPED_OK = (typeof Uint8Array !== 'undefined') && 408 | (typeof Uint16Array !== 'undefined') && 409 | (typeof Int32Array !== 'undefined'); 410 | 411 | 412 | exports.assign = function (obj /*from1, from2, from3, ...*/) { 413 | var sources = Array.prototype.slice.call(arguments, 1); 414 | while (sources.length) { 415 | var source = sources.shift(); 416 | if (!source) { continue; } 417 | 418 | if (typeof source !== 'object') { 419 | throw new TypeError(source + 'must be non-object'); 420 | } 421 | 422 | for (var p in source) { 423 | if (source.hasOwnProperty(p)) { 424 | obj[p] = source[p]; 425 | } 426 | } 427 | } 428 | 429 | return obj; 430 | }; 431 | 432 | 433 | // reduce buffer size, avoiding mem copy 434 | exports.shrinkBuf = function (buf, size) { 435 | if (buf.length === size) { return buf; } 436 | if (buf.subarray) { return buf.subarray(0, size); } 437 | buf.length = size; 438 | return buf; 439 | }; 440 | 441 | 442 | var fnTyped = { 443 | arraySet: function (dest, src, src_offs, len, dest_offs) { 444 | if (src.subarray && dest.subarray) { 445 | dest.set(src.subarray(src_offs, src_offs + len), dest_offs); 446 | return; 447 | } 448 | // Fallback to ordinary array 449 | for (var i = 0; i < len; i++) { 450 | dest[dest_offs + i] = src[src_offs + i]; 451 | } 452 | }, 453 | // Join array of chunks to single array. 454 | flattenChunks: function (chunks) { 455 | var i, l, len, pos, chunk, result; 456 | 457 | // calculate data length 458 | len = 0; 459 | for (i = 0, l = chunks.length; i < l; i++) { 460 | len += chunks[i].length; 461 | } 462 | 463 | // join chunks 464 | result = new Uint8Array(len); 465 | pos = 0; 466 | for (i = 0, l = chunks.length; i < l; i++) { 467 | chunk = chunks[i]; 468 | result.set(chunk, pos); 469 | pos += chunk.length; 470 | } 471 | 472 | return result; 473 | } 474 | }; 475 | 476 | var fnUntyped = { 477 | arraySet: function (dest, src, src_offs, len, dest_offs) { 478 | for (var i = 0; i < len; i++) { 479 | dest[dest_offs + i] = src[src_offs + i]; 480 | } 481 | }, 482 | // Join array of chunks to single array. 483 | flattenChunks: function (chunks) { 484 | return [].concat.apply([], chunks); 485 | } 486 | }; 487 | 488 | 489 | // Enable/Disable typed arrays use, for testing 490 | // 491 | exports.setTyped = function (on) { 492 | if (on) { 493 | exports.Buf8 = Uint8Array; 494 | exports.Buf16 = Uint16Array; 495 | exports.Buf32 = Int32Array; 496 | exports.assign(exports, fnTyped); 497 | } else { 498 | exports.Buf8 = Array; 499 | exports.Buf16 = Array; 500 | exports.Buf32 = Array; 501 | exports.assign(exports, fnUntyped); 502 | } 503 | }; 504 | 505 | exports.setTyped(TYPED_OK); 506 | 507 | },{}],3:[function(require,module,exports){ 508 | // String encode/decode helpers 509 | 'use strict'; 510 | 511 | 512 | var utils = require('./common'); 513 | 514 | 515 | // Quick check if we can use fast array to bin string conversion 516 | // 517 | // - apply(Array) can fail on Android 2.2 518 | // - apply(Uint8Array) can fail on iOS 5.1 Safary 519 | // 520 | var STR_APPLY_OK = true; 521 | var STR_APPLY_UIA_OK = true; 522 | 523 | try { String.fromCharCode.apply(null, [ 0 ]); } catch (__) { STR_APPLY_OK = false; } 524 | try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; } 525 | 526 | 527 | // Table with utf8 lengths (calculated by first byte of sequence) 528 | // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS, 529 | // because max possible codepoint is 0x10ffff 530 | var _utf8len = new utils.Buf8(256); 531 | for (var q = 0; q < 256; q++) { 532 | _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1); 533 | } 534 | _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start 535 | 536 | 537 | // convert string to array (typed, when possible) 538 | exports.string2buf = function (str) { 539 | var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0; 540 | 541 | // count binary size 542 | for (m_pos = 0; m_pos < str_len; m_pos++) { 543 | c = str.charCodeAt(m_pos); 544 | if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) { 545 | c2 = str.charCodeAt(m_pos + 1); 546 | if ((c2 & 0xfc00) === 0xdc00) { 547 | c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00); 548 | m_pos++; 549 | } 550 | } 551 | buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4; 552 | } 553 | 554 | // allocate buffer 555 | buf = new utils.Buf8(buf_len); 556 | 557 | // convert 558 | for (i = 0, m_pos = 0; i < buf_len; m_pos++) { 559 | c = str.charCodeAt(m_pos); 560 | if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) { 561 | c2 = str.charCodeAt(m_pos + 1); 562 | if ((c2 & 0xfc00) === 0xdc00) { 563 | c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00); 564 | m_pos++; 565 | } 566 | } 567 | if (c < 0x80) { 568 | /* one byte */ 569 | buf[i++] = c; 570 | } else if (c < 0x800) { 571 | /* two bytes */ 572 | buf[i++] = 0xC0 | (c >>> 6); 573 | buf[i++] = 0x80 | (c & 0x3f); 574 | } else if (c < 0x10000) { 575 | /* three bytes */ 576 | buf[i++] = 0xE0 | (c >>> 12); 577 | buf[i++] = 0x80 | (c >>> 6 & 0x3f); 578 | buf[i++] = 0x80 | (c & 0x3f); 579 | } else { 580 | /* four bytes */ 581 | buf[i++] = 0xf0 | (c >>> 18); 582 | buf[i++] = 0x80 | (c >>> 12 & 0x3f); 583 | buf[i++] = 0x80 | (c >>> 6 & 0x3f); 584 | buf[i++] = 0x80 | (c & 0x3f); 585 | } 586 | } 587 | 588 | return buf; 589 | }; 590 | 591 | // Helper (used in 2 places) 592 | function buf2binstring(buf, len) { 593 | // use fallback for big arrays to avoid stack overflow 594 | if (len < 65537) { 595 | if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) { 596 | return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len)); 597 | } 598 | } 599 | 600 | var result = ''; 601 | for (var i = 0; i < len; i++) { 602 | result += String.fromCharCode(buf[i]); 603 | } 604 | return result; 605 | } 606 | 607 | 608 | // Convert byte array to binary string 609 | exports.buf2binstring = function (buf) { 610 | return buf2binstring(buf, buf.length); 611 | }; 612 | 613 | 614 | // Convert binary string (typed, when possible) 615 | exports.binstring2buf = function (str) { 616 | var buf = new utils.Buf8(str.length); 617 | for (var i = 0, len = buf.length; i < len; i++) { 618 | buf[i] = str.charCodeAt(i); 619 | } 620 | return buf; 621 | }; 622 | 623 | 624 | // convert array to string 625 | exports.buf2string = function (buf, max) { 626 | var i, out, c, c_len; 627 | var len = max || buf.length; 628 | 629 | // Reserve max possible length (2 words per char) 630 | // NB: by unknown reasons, Array is significantly faster for 631 | // String.fromCharCode.apply than Uint16Array. 632 | var utf16buf = new Array(len * 2); 633 | 634 | for (out = 0, i = 0; i < len;) { 635 | c = buf[i++]; 636 | // quick process ascii 637 | if (c < 0x80) { utf16buf[out++] = c; continue; } 638 | 639 | c_len = _utf8len[c]; 640 | // skip 5 & 6 byte codes 641 | if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; } 642 | 643 | // apply mask on first byte 644 | c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; 645 | // join the rest 646 | while (c_len > 1 && i < len) { 647 | c = (c << 6) | (buf[i++] & 0x3f); 648 | c_len--; 649 | } 650 | 651 | // terminated by end of string? 652 | if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; } 653 | 654 | if (c < 0x10000) { 655 | utf16buf[out++] = c; 656 | } else { 657 | c -= 0x10000; 658 | utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff); 659 | utf16buf[out++] = 0xdc00 | (c & 0x3ff); 660 | } 661 | } 662 | 663 | return buf2binstring(utf16buf, out); 664 | }; 665 | 666 | 667 | // Calculate max possible position in utf8 buffer, 668 | // that will not break sequence. If that's not possible 669 | // - (very small limits) return max size as is. 670 | // 671 | // buf[] - utf8 bytes array 672 | // max - length limit (mandatory); 673 | exports.utf8border = function (buf, max) { 674 | var pos; 675 | 676 | max = max || buf.length; 677 | if (max > buf.length) { max = buf.length; } 678 | 679 | // go back from last position, until start of sequence found 680 | pos = max - 1; 681 | while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; } 682 | 683 | // Fuckup - very small and broken sequence, 684 | // return max, because we should return something anyway. 685 | if (pos < 0) { return max; } 686 | 687 | // If we came to start of buffer - that means vuffer is too small, 688 | // return max too. 689 | if (pos === 0) { return max; } 690 | 691 | return (pos + _utf8len[buf[pos]] > max) ? pos : max; 692 | }; 693 | 694 | },{"./common":2}],4:[function(require,module,exports){ 695 | 'use strict'; 696 | 697 | // Note: adler32 takes 12% for level 0 and 2% for level 6. 698 | // It doesn't worth to make additional optimizationa as in original. 699 | // Small size is preferable. 700 | 701 | // (C) 1995-2013 Jean-loup Gailly and Mark Adler 702 | // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin 703 | // 704 | // This software is provided 'as-is', without any express or implied 705 | // warranty. In no event will the authors be held liable for any damages 706 | // arising from the use of this software. 707 | // 708 | // Permission is granted to anyone to use this software for any purpose, 709 | // including commercial applications, and to alter it and redistribute it 710 | // freely, subject to the following restrictions: 711 | // 712 | // 1. The origin of this software must not be misrepresented; you must not 713 | // claim that you wrote the original software. If you use this software 714 | // in a product, an acknowledgment in the product documentation would be 715 | // appreciated but is not required. 716 | // 2. Altered source versions must be plainly marked as such, and must not be 717 | // misrepresented as being the original software. 718 | // 3. This notice may not be removed or altered from any source distribution. 719 | 720 | function adler32(adler, buf, len, pos) { 721 | var s1 = (adler & 0xffff) |0, 722 | s2 = ((adler >>> 16) & 0xffff) |0, 723 | n = 0; 724 | 725 | while (len !== 0) { 726 | // Set limit ~ twice less than 5552, to keep 727 | // s2 in 31-bits, because we force signed ints. 728 | // in other case %= will fail. 729 | n = len > 2000 ? 2000 : len; 730 | len -= n; 731 | 732 | do { 733 | s1 = (s1 + buf[pos++]) |0; 734 | s2 = (s2 + s1) |0; 735 | } while (--n); 736 | 737 | s1 %= 65521; 738 | s2 %= 65521; 739 | } 740 | 741 | return (s1 | (s2 << 16)) |0; 742 | } 743 | 744 | 745 | module.exports = adler32; 746 | 747 | },{}],5:[function(require,module,exports){ 748 | 'use strict'; 749 | 750 | // Note: we can't get significant speed boost here. 751 | // So write code to minimize size - no pregenerated tables 752 | // and array tools dependencies. 753 | 754 | // (C) 1995-2013 Jean-loup Gailly and Mark Adler 755 | // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin 756 | // 757 | // This software is provided 'as-is', without any express or implied 758 | // warranty. In no event will the authors be held liable for any damages 759 | // arising from the use of this software. 760 | // 761 | // Permission is granted to anyone to use this software for any purpose, 762 | // including commercial applications, and to alter it and redistribute it 763 | // freely, subject to the following restrictions: 764 | // 765 | // 1. The origin of this software must not be misrepresented; you must not 766 | // claim that you wrote the original software. If you use this software 767 | // in a product, an acknowledgment in the product documentation would be 768 | // appreciated but is not required. 769 | // 2. Altered source versions must be plainly marked as such, and must not be 770 | // misrepresented as being the original software. 771 | // 3. This notice may not be removed or altered from any source distribution. 772 | 773 | // Use ordinary array, since untyped makes no boost here 774 | function makeTable() { 775 | var c, table = []; 776 | 777 | for (var n = 0; n < 256; n++) { 778 | c = n; 779 | for (var k = 0; k < 8; k++) { 780 | c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)); 781 | } 782 | table[n] = c; 783 | } 784 | 785 | return table; 786 | } 787 | 788 | // Create table on load. Just 255 signed longs. Not a problem. 789 | var crcTable = makeTable(); 790 | 791 | 792 | function crc32(crc, buf, len, pos) { 793 | var t = crcTable, 794 | end = pos + len; 795 | 796 | crc ^= -1; 797 | 798 | for (var i = pos; i < end; i++) { 799 | crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF]; 800 | } 801 | 802 | return (crc ^ (-1)); // >>> 0; 803 | } 804 | 805 | 806 | module.exports = crc32; 807 | 808 | },{}],6:[function(require,module,exports){ 809 | 'use strict'; 810 | 811 | // (C) 1995-2013 Jean-loup Gailly and Mark Adler 812 | // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin 813 | // 814 | // This software is provided 'as-is', without any express or implied 815 | // warranty. In no event will the authors be held liable for any damages 816 | // arising from the use of this software. 817 | // 818 | // Permission is granted to anyone to use this software for any purpose, 819 | // including commercial applications, and to alter it and redistribute it 820 | // freely, subject to the following restrictions: 821 | // 822 | // 1. The origin of this software must not be misrepresented; you must not 823 | // claim that you wrote the original software. If you use this software 824 | // in a product, an acknowledgment in the product documentation would be 825 | // appreciated but is not required. 826 | // 2. Altered source versions must be plainly marked as such, and must not be 827 | // misrepresented as being the original software. 828 | // 3. This notice may not be removed or altered from any source distribution. 829 | 830 | var utils = require('../utils/common'); 831 | var trees = require('./trees'); 832 | var adler32 = require('./adler32'); 833 | var crc32 = require('./crc32'); 834 | var msg = require('./messages'); 835 | 836 | /* Public constants ==========================================================*/ 837 | /* ===========================================================================*/ 838 | 839 | 840 | /* Allowed flush values; see deflate() and inflate() below for details */ 841 | var Z_NO_FLUSH = 0; 842 | var Z_PARTIAL_FLUSH = 1; 843 | //var Z_SYNC_FLUSH = 2; 844 | var Z_FULL_FLUSH = 3; 845 | var Z_FINISH = 4; 846 | var Z_BLOCK = 5; 847 | //var Z_TREES = 6; 848 | 849 | 850 | /* Return codes for the compression/decompression functions. Negative values 851 | * are errors, positive values are used for special but normal events. 852 | */ 853 | var Z_OK = 0; 854 | var Z_STREAM_END = 1; 855 | //var Z_NEED_DICT = 2; 856 | //var Z_ERRNO = -1; 857 | var Z_STREAM_ERROR = -2; 858 | var Z_DATA_ERROR = -3; 859 | //var Z_MEM_ERROR = -4; 860 | var Z_BUF_ERROR = -5; 861 | //var Z_VERSION_ERROR = -6; 862 | 863 | 864 | /* compression levels */ 865 | //var Z_NO_COMPRESSION = 0; 866 | //var Z_BEST_SPEED = 1; 867 | //var Z_BEST_COMPRESSION = 9; 868 | var Z_DEFAULT_COMPRESSION = -1; 869 | 870 | 871 | var Z_FILTERED = 1; 872 | var Z_HUFFMAN_ONLY = 2; 873 | var Z_RLE = 3; 874 | var Z_FIXED = 4; 875 | var Z_DEFAULT_STRATEGY = 0; 876 | 877 | /* Possible values of the data_type field (though see inflate()) */ 878 | //var Z_BINARY = 0; 879 | //var Z_TEXT = 1; 880 | //var Z_ASCII = 1; // = Z_TEXT 881 | var Z_UNKNOWN = 2; 882 | 883 | 884 | /* The deflate compression method */ 885 | var Z_DEFLATED = 8; 886 | 887 | /*============================================================================*/ 888 | 889 | 890 | var MAX_MEM_LEVEL = 9; 891 | /* Maximum value for memLevel in deflateInit2 */ 892 | var MAX_WBITS = 15; 893 | /* 32K LZ77 window */ 894 | var DEF_MEM_LEVEL = 8; 895 | 896 | 897 | var LENGTH_CODES = 29; 898 | /* number of length codes, not counting the special END_BLOCK code */ 899 | var LITERALS = 256; 900 | /* number of literal bytes 0..255 */ 901 | var L_CODES = LITERALS + 1 + LENGTH_CODES; 902 | /* number of Literal or Length codes, including the END_BLOCK code */ 903 | var D_CODES = 30; 904 | /* number of distance codes */ 905 | var BL_CODES = 19; 906 | /* number of codes used to transfer the bit lengths */ 907 | var HEAP_SIZE = 2 * L_CODES + 1; 908 | /* maximum heap size */ 909 | var MAX_BITS = 15; 910 | /* All codes must not exceed MAX_BITS bits */ 911 | 912 | var MIN_MATCH = 3; 913 | var MAX_MATCH = 258; 914 | var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1); 915 | 916 | var PRESET_DICT = 0x20; 917 | 918 | var INIT_STATE = 42; 919 | var EXTRA_STATE = 69; 920 | var NAME_STATE = 73; 921 | var COMMENT_STATE = 91; 922 | var HCRC_STATE = 103; 923 | var BUSY_STATE = 113; 924 | var FINISH_STATE = 666; 925 | 926 | var BS_NEED_MORE = 1; /* block not completed, need more input or more output */ 927 | var BS_BLOCK_DONE = 2; /* block flush performed */ 928 | var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */ 929 | var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */ 930 | 931 | var OS_CODE = 0x03; // Unix :) . Don't detect, use this default. 932 | 933 | function err(strm, errorCode) { 934 | strm.msg = msg[errorCode]; 935 | return errorCode; 936 | } 937 | 938 | function rank(f) { 939 | return ((f) << 1) - ((f) > 4 ? 9 : 0); 940 | } 941 | 942 | function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } } 943 | 944 | 945 | /* ========================================================================= 946 | * Flush as much pending output as possible. All deflate() output goes 947 | * through this function so some applications may wish to modify it 948 | * to avoid allocating a large strm->output buffer and copying into it. 949 | * (See also read_buf()). 950 | */ 951 | function flush_pending(strm) { 952 | var s = strm.state; 953 | 954 | //_tr_flush_bits(s); 955 | var len = s.pending; 956 | if (len > strm.avail_out) { 957 | len = strm.avail_out; 958 | } 959 | if (len === 0) { return; } 960 | 961 | utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out); 962 | strm.next_out += len; 963 | s.pending_out += len; 964 | strm.total_out += len; 965 | strm.avail_out -= len; 966 | s.pending -= len; 967 | if (s.pending === 0) { 968 | s.pending_out = 0; 969 | } 970 | } 971 | 972 | 973 | function flush_block_only(s, last) { 974 | trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last); 975 | s.block_start = s.strstart; 976 | flush_pending(s.strm); 977 | } 978 | 979 | 980 | function put_byte(s, b) { 981 | s.pending_buf[s.pending++] = b; 982 | } 983 | 984 | 985 | /* ========================================================================= 986 | * Put a short in the pending buffer. The 16-bit value is put in MSB order. 987 | * IN assertion: the stream state is correct and there is enough room in 988 | * pending_buf. 989 | */ 990 | function putShortMSB(s, b) { 991 | // put_byte(s, (Byte)(b >> 8)); 992 | // put_byte(s, (Byte)(b & 0xff)); 993 | s.pending_buf[s.pending++] = (b >>> 8) & 0xff; 994 | s.pending_buf[s.pending++] = b & 0xff; 995 | } 996 | 997 | 998 | /* =========================================================================== 999 | * Read a new buffer from the current input stream, update the adler32 1000 | * and total number of bytes read. All deflate() input goes through 1001 | * this function so some applications may wish to modify it to avoid 1002 | * allocating a large strm->input buffer and copying from it. 1003 | * (See also flush_pending()). 1004 | */ 1005 | function read_buf(strm, buf, start, size) { 1006 | var len = strm.avail_in; 1007 | 1008 | if (len > size) { len = size; } 1009 | if (len === 0) { return 0; } 1010 | 1011 | strm.avail_in -= len; 1012 | 1013 | // zmemcpy(buf, strm->next_in, len); 1014 | utils.arraySet(buf, strm.input, strm.next_in, len, start); 1015 | if (strm.state.wrap === 1) { 1016 | strm.adler = adler32(strm.adler, buf, len, start); 1017 | } 1018 | 1019 | else if (strm.state.wrap === 2) { 1020 | strm.adler = crc32(strm.adler, buf, len, start); 1021 | } 1022 | 1023 | strm.next_in += len; 1024 | strm.total_in += len; 1025 | 1026 | return len; 1027 | } 1028 | 1029 | 1030 | /* =========================================================================== 1031 | * Set match_start to the longest match starting at the given string and 1032 | * return its length. Matches shorter or equal to prev_length are discarded, 1033 | * in which case the result is equal to prev_length and match_start is 1034 | * garbage. 1035 | * IN assertions: cur_match is the head of the hash chain for the current 1036 | * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 1037 | * OUT assertion: the match length is not greater than s->lookahead. 1038 | */ 1039 | function longest_match(s, cur_match) { 1040 | var chain_length = s.max_chain_length; /* max hash chain length */ 1041 | var scan = s.strstart; /* current string */ 1042 | var match; /* matched string */ 1043 | var len; /* length of current match */ 1044 | var best_len = s.prev_length; /* best match length so far */ 1045 | var nice_match = s.nice_match; /* stop if match long enough */ 1046 | var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ? 1047 | s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/; 1048 | 1049 | var _win = s.window; // shortcut 1050 | 1051 | var wmask = s.w_mask; 1052 | var prev = s.prev; 1053 | 1054 | /* Stop when cur_match becomes <= limit. To simplify the code, 1055 | * we prevent matches with the string of window index 0. 1056 | */ 1057 | 1058 | var strend = s.strstart + MAX_MATCH; 1059 | var scan_end1 = _win[scan + best_len - 1]; 1060 | var scan_end = _win[scan + best_len]; 1061 | 1062 | /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. 1063 | * It is easy to get rid of this optimization if necessary. 1064 | */ 1065 | // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); 1066 | 1067 | /* Do not waste too much time if we already have a good match: */ 1068 | if (s.prev_length >= s.good_match) { 1069 | chain_length >>= 2; 1070 | } 1071 | /* Do not look for matches beyond the end of the input. This is necessary 1072 | * to make deflate deterministic. 1073 | */ 1074 | if (nice_match > s.lookahead) { nice_match = s.lookahead; } 1075 | 1076 | // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); 1077 | 1078 | do { 1079 | // Assert(cur_match < s->strstart, "no future"); 1080 | match = cur_match; 1081 | 1082 | /* Skip to next match if the match length cannot increase 1083 | * or if the match length is less than 2. Note that the checks below 1084 | * for insufficient lookahead only occur occasionally for performance 1085 | * reasons. Therefore uninitialized memory will be accessed, and 1086 | * conditional jumps will be made that depend on those values. 1087 | * However the length of the match is limited to the lookahead, so 1088 | * the output of deflate is not affected by the uninitialized values. 1089 | */ 1090 | 1091 | if (_win[match + best_len] !== scan_end || 1092 | _win[match + best_len - 1] !== scan_end1 || 1093 | _win[match] !== _win[scan] || 1094 | _win[++match] !== _win[scan + 1]) { 1095 | continue; 1096 | } 1097 | 1098 | /* The check at best_len-1 can be removed because it will be made 1099 | * again later. (This heuristic is not always a win.) 1100 | * It is not necessary to compare scan[2] and match[2] since they 1101 | * are always equal when the other bytes match, given that 1102 | * the hash keys are equal and that HASH_BITS >= 8. 1103 | */ 1104 | scan += 2; 1105 | match++; 1106 | // Assert(*scan == *match, "match[2]?"); 1107 | 1108 | /* We check for insufficient lookahead only every 8th comparison; 1109 | * the 256th check will be made at strstart+258. 1110 | */ 1111 | do { 1112 | /*jshint noempty:false*/ 1113 | } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && 1114 | _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && 1115 | _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && 1116 | _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && 1117 | scan < strend); 1118 | 1119 | // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 1120 | 1121 | len = MAX_MATCH - (strend - scan); 1122 | scan = strend - MAX_MATCH; 1123 | 1124 | if (len > best_len) { 1125 | s.match_start = cur_match; 1126 | best_len = len; 1127 | if (len >= nice_match) { 1128 | break; 1129 | } 1130 | scan_end1 = _win[scan + best_len - 1]; 1131 | scan_end = _win[scan + best_len]; 1132 | } 1133 | } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0); 1134 | 1135 | if (best_len <= s.lookahead) { 1136 | return best_len; 1137 | } 1138 | return s.lookahead; 1139 | } 1140 | 1141 | 1142 | /* =========================================================================== 1143 | * Fill the window when the lookahead becomes insufficient. 1144 | * Updates strstart and lookahead. 1145 | * 1146 | * IN assertion: lookahead < MIN_LOOKAHEAD 1147 | * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD 1148 | * At least one byte has been read, or avail_in == 0; reads are 1149 | * performed for at least two bytes (required for the zip translate_eol 1150 | * option -- not supported here). 1151 | */ 1152 | function fill_window(s) { 1153 | var _w_size = s.w_size; 1154 | var p, n, m, more, str; 1155 | 1156 | //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); 1157 | 1158 | do { 1159 | more = s.window_size - s.lookahead - s.strstart; 1160 | 1161 | // JS ints have 32 bit, block below not needed 1162 | /* Deal with !@#$% 64K limit: */ 1163 | //if (sizeof(int) <= 2) { 1164 | // if (more == 0 && s->strstart == 0 && s->lookahead == 0) { 1165 | // more = wsize; 1166 | // 1167 | // } else if (more == (unsigned)(-1)) { 1168 | // /* Very unlikely, but possible on 16 bit machine if 1169 | // * strstart == 0 && lookahead == 1 (input done a byte at time) 1170 | // */ 1171 | // more--; 1172 | // } 1173 | //} 1174 | 1175 | 1176 | /* If the window is almost full and there is insufficient lookahead, 1177 | * move the upper half to the lower one to make room in the upper half. 1178 | */ 1179 | if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) { 1180 | 1181 | utils.arraySet(s.window, s.window, _w_size, _w_size, 0); 1182 | s.match_start -= _w_size; 1183 | s.strstart -= _w_size; 1184 | /* we now have strstart >= MAX_DIST */ 1185 | s.block_start -= _w_size; 1186 | 1187 | /* Slide the hash table (could be avoided with 32 bit values 1188 | at the expense of memory usage). We slide even when level == 0 1189 | to keep the hash table consistent if we switch back to level > 0 1190 | later. (Using level 0 permanently is not an optimal usage of 1191 | zlib, so we don't care about this pathological case.) 1192 | */ 1193 | 1194 | n = s.hash_size; 1195 | p = n; 1196 | do { 1197 | m = s.head[--p]; 1198 | s.head[p] = (m >= _w_size ? m - _w_size : 0); 1199 | } while (--n); 1200 | 1201 | n = _w_size; 1202 | p = n; 1203 | do { 1204 | m = s.prev[--p]; 1205 | s.prev[p] = (m >= _w_size ? m - _w_size : 0); 1206 | /* If n is not on any hash chain, prev[n] is garbage but 1207 | * its value will never be used. 1208 | */ 1209 | } while (--n); 1210 | 1211 | more += _w_size; 1212 | } 1213 | if (s.strm.avail_in === 0) { 1214 | break; 1215 | } 1216 | 1217 | /* If there was no sliding: 1218 | * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && 1219 | * more == window_size - lookahead - strstart 1220 | * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) 1221 | * => more >= window_size - 2*WSIZE + 2 1222 | * In the BIG_MEM or MMAP case (not yet supported), 1223 | * window_size == input_size + MIN_LOOKAHEAD && 1224 | * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. 1225 | * Otherwise, window_size == 2*WSIZE so more >= 2. 1226 | * If there was sliding, more >= WSIZE. So in all cases, more >= 2. 1227 | */ 1228 | //Assert(more >= 2, "more < 2"); 1229 | n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more); 1230 | s.lookahead += n; 1231 | 1232 | /* Initialize the hash value now that we have some input: */ 1233 | if (s.lookahead + s.insert >= MIN_MATCH) { 1234 | str = s.strstart - s.insert; 1235 | s.ins_h = s.window[str]; 1236 | 1237 | /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */ 1238 | s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask; 1239 | //#if MIN_MATCH != 3 1240 | // Call update_hash() MIN_MATCH-3 more times 1241 | //#endif 1242 | while (s.insert) { 1243 | /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */ 1244 | s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask; 1245 | 1246 | s.prev[str & s.w_mask] = s.head[s.ins_h]; 1247 | s.head[s.ins_h] = str; 1248 | str++; 1249 | s.insert--; 1250 | if (s.lookahead + s.insert < MIN_MATCH) { 1251 | break; 1252 | } 1253 | } 1254 | } 1255 | /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, 1256 | * but this is not important since only literal bytes will be emitted. 1257 | */ 1258 | 1259 | } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0); 1260 | 1261 | /* If the WIN_INIT bytes after the end of the current data have never been 1262 | * written, then zero those bytes in order to avoid memory check reports of 1263 | * the use of uninitialized (or uninitialised as Julian writes) bytes by 1264 | * the longest match routines. Update the high water mark for the next 1265 | * time through here. WIN_INIT is set to MAX_MATCH since the longest match 1266 | * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. 1267 | */ 1268 | // if (s.high_water < s.window_size) { 1269 | // var curr = s.strstart + s.lookahead; 1270 | // var init = 0; 1271 | // 1272 | // if (s.high_water < curr) { 1273 | // /* Previous high water mark below current data -- zero WIN_INIT 1274 | // * bytes or up to end of window, whichever is less. 1275 | // */ 1276 | // init = s.window_size - curr; 1277 | // if (init > WIN_INIT) 1278 | // init = WIN_INIT; 1279 | // zmemzero(s->window + curr, (unsigned)init); 1280 | // s->high_water = curr + init; 1281 | // } 1282 | // else if (s->high_water < (ulg)curr + WIN_INIT) { 1283 | // /* High water mark at or above current data, but below current data 1284 | // * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up 1285 | // * to end of window, whichever is less. 1286 | // */ 1287 | // init = (ulg)curr + WIN_INIT - s->high_water; 1288 | // if (init > s->window_size - s->high_water) 1289 | // init = s->window_size - s->high_water; 1290 | // zmemzero(s->window + s->high_water, (unsigned)init); 1291 | // s->high_water += init; 1292 | // } 1293 | // } 1294 | // 1295 | // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, 1296 | // "not enough room for search"); 1297 | } 1298 | 1299 | /* =========================================================================== 1300 | * Copy without compression as much as possible from the input stream, return 1301 | * the current block state. 1302 | * This function does not insert new strings in the dictionary since 1303 | * uncompressible data is probably not useful. This function is used 1304 | * only for the level=0 compression option. 1305 | * NOTE: this function should be optimized to avoid extra copying from 1306 | * window to pending_buf. 1307 | */ 1308 | function deflate_stored(s, flush) { 1309 | /* Stored blocks are limited to 0xffff bytes, pending_buf is limited 1310 | * to pending_buf_size, and each stored block has a 5 byte header: 1311 | */ 1312 | var max_block_size = 0xffff; 1313 | 1314 | if (max_block_size > s.pending_buf_size - 5) { 1315 | max_block_size = s.pending_buf_size - 5; 1316 | } 1317 | 1318 | /* Copy as much as possible from input to output: */ 1319 | for (;;) { 1320 | /* Fill the window as much as possible: */ 1321 | if (s.lookahead <= 1) { 1322 | 1323 | //Assert(s->strstart < s->w_size+MAX_DIST(s) || 1324 | // s->block_start >= (long)s->w_size, "slide too late"); 1325 | // if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) || 1326 | // s.block_start >= s.w_size)) { 1327 | // throw new Error("slide too late"); 1328 | // } 1329 | 1330 | fill_window(s); 1331 | if (s.lookahead === 0 && flush === Z_NO_FLUSH) { 1332 | return BS_NEED_MORE; 1333 | } 1334 | 1335 | if (s.lookahead === 0) { 1336 | break; 1337 | } 1338 | /* flush the current block */ 1339 | } 1340 | //Assert(s->block_start >= 0L, "block gone"); 1341 | // if (s.block_start < 0) throw new Error("block gone"); 1342 | 1343 | s.strstart += s.lookahead; 1344 | s.lookahead = 0; 1345 | 1346 | /* Emit a stored block if pending_buf will be full: */ 1347 | var max_start = s.block_start + max_block_size; 1348 | 1349 | if (s.strstart === 0 || s.strstart >= max_start) { 1350 | /* strstart == 0 is possible when wraparound on 16-bit machine */ 1351 | s.lookahead = s.strstart - max_start; 1352 | s.strstart = max_start; 1353 | /*** FLUSH_BLOCK(s, 0); ***/ 1354 | flush_block_only(s, false); 1355 | if (s.strm.avail_out === 0) { 1356 | return BS_NEED_MORE; 1357 | } 1358 | /***/ 1359 | 1360 | 1361 | } 1362 | /* Flush if we may have to slide, otherwise block_start may become 1363 | * negative and the data will be gone: 1364 | */ 1365 | if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) { 1366 | /*** FLUSH_BLOCK(s, 0); ***/ 1367 | flush_block_only(s, false); 1368 | if (s.strm.avail_out === 0) { 1369 | return BS_NEED_MORE; 1370 | } 1371 | /***/ 1372 | } 1373 | } 1374 | 1375 | s.insert = 0; 1376 | 1377 | if (flush === Z_FINISH) { 1378 | /*** FLUSH_BLOCK(s, 1); ***/ 1379 | flush_block_only(s, true); 1380 | if (s.strm.avail_out === 0) { 1381 | return BS_FINISH_STARTED; 1382 | } 1383 | /***/ 1384 | return BS_FINISH_DONE; 1385 | } 1386 | 1387 | if (s.strstart > s.block_start) { 1388 | /*** FLUSH_BLOCK(s, 0); ***/ 1389 | flush_block_only(s, false); 1390 | if (s.strm.avail_out === 0) { 1391 | return BS_NEED_MORE; 1392 | } 1393 | /***/ 1394 | } 1395 | 1396 | return BS_NEED_MORE; 1397 | } 1398 | 1399 | /* =========================================================================== 1400 | * Compress as much as possible from the input stream, return the current 1401 | * block state. 1402 | * This function does not perform lazy evaluation of matches and inserts 1403 | * new strings in the dictionary only for unmatched strings or for short 1404 | * matches. It is used only for the fast compression options. 1405 | */ 1406 | function deflate_fast(s, flush) { 1407 | var hash_head; /* head of the hash chain */ 1408 | var bflush; /* set if current block must be flushed */ 1409 | 1410 | for (;;) { 1411 | /* Make sure that we always have enough lookahead, except 1412 | * at the end of the input file. We need MAX_MATCH bytes 1413 | * for the next match, plus MIN_MATCH bytes to insert the 1414 | * string following the next match. 1415 | */ 1416 | if (s.lookahead < MIN_LOOKAHEAD) { 1417 | fill_window(s); 1418 | if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { 1419 | return BS_NEED_MORE; 1420 | } 1421 | if (s.lookahead === 0) { 1422 | break; /* flush the current block */ 1423 | } 1424 | } 1425 | 1426 | /* Insert the string window[strstart .. strstart+2] in the 1427 | * dictionary, and set hash_head to the head of the hash chain: 1428 | */ 1429 | hash_head = 0/*NIL*/; 1430 | if (s.lookahead >= MIN_MATCH) { 1431 | /*** INSERT_STRING(s, s.strstart, hash_head); ***/ 1432 | s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; 1433 | hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; 1434 | s.head[s.ins_h] = s.strstart; 1435 | /***/ 1436 | } 1437 | 1438 | /* Find the longest match, discarding those <= prev_length. 1439 | * At this point we have always match_length < MIN_MATCH 1440 | */ 1441 | if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) { 1442 | /* To simplify the code, we prevent matches with the string 1443 | * of window index 0 (in particular we have to avoid a match 1444 | * of the string with itself at the start of the input file). 1445 | */ 1446 | s.match_length = longest_match(s, hash_head); 1447 | /* longest_match() sets match_start */ 1448 | } 1449 | if (s.match_length >= MIN_MATCH) { 1450 | // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only 1451 | 1452 | /*** _tr_tally_dist(s, s.strstart - s.match_start, 1453 | s.match_length - MIN_MATCH, bflush); ***/ 1454 | bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH); 1455 | 1456 | s.lookahead -= s.match_length; 1457 | 1458 | /* Insert new strings in the hash table only if the match length 1459 | * is not too large. This saves time but degrades compression. 1460 | */ 1461 | if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) { 1462 | s.match_length--; /* string at strstart already in table */ 1463 | do { 1464 | s.strstart++; 1465 | /*** INSERT_STRING(s, s.strstart, hash_head); ***/ 1466 | s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; 1467 | hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; 1468 | s.head[s.ins_h] = s.strstart; 1469 | /***/ 1470 | /* strstart never exceeds WSIZE-MAX_MATCH, so there are 1471 | * always MIN_MATCH bytes ahead. 1472 | */ 1473 | } while (--s.match_length !== 0); 1474 | s.strstart++; 1475 | } else 1476 | { 1477 | s.strstart += s.match_length; 1478 | s.match_length = 0; 1479 | s.ins_h = s.window[s.strstart]; 1480 | /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */ 1481 | s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask; 1482 | 1483 | //#if MIN_MATCH != 3 1484 | // Call UPDATE_HASH() MIN_MATCH-3 more times 1485 | //#endif 1486 | /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not 1487 | * matter since it will be recomputed at next deflate call. 1488 | */ 1489 | } 1490 | } else { 1491 | /* No match, output a literal byte */ 1492 | //Tracevv((stderr,"%c", s.window[s.strstart])); 1493 | /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ 1494 | bflush = trees._tr_tally(s, 0, s.window[s.strstart]); 1495 | 1496 | s.lookahead--; 1497 | s.strstart++; 1498 | } 1499 | if (bflush) { 1500 | /*** FLUSH_BLOCK(s, 0); ***/ 1501 | flush_block_only(s, false); 1502 | if (s.strm.avail_out === 0) { 1503 | return BS_NEED_MORE; 1504 | } 1505 | /***/ 1506 | } 1507 | } 1508 | s.insert = ((s.strstart < (MIN_MATCH - 1)) ? s.strstart : MIN_MATCH - 1); 1509 | if (flush === Z_FINISH) { 1510 | /*** FLUSH_BLOCK(s, 1); ***/ 1511 | flush_block_only(s, true); 1512 | if (s.strm.avail_out === 0) { 1513 | return BS_FINISH_STARTED; 1514 | } 1515 | /***/ 1516 | return BS_FINISH_DONE; 1517 | } 1518 | if (s.last_lit) { 1519 | /*** FLUSH_BLOCK(s, 0); ***/ 1520 | flush_block_only(s, false); 1521 | if (s.strm.avail_out === 0) { 1522 | return BS_NEED_MORE; 1523 | } 1524 | /***/ 1525 | } 1526 | return BS_BLOCK_DONE; 1527 | } 1528 | 1529 | /* =========================================================================== 1530 | * Same as above, but achieves better compression. We use a lazy 1531 | * evaluation for matches: a match is finally adopted only if there is 1532 | * no better match at the next window position. 1533 | */ 1534 | function deflate_slow(s, flush) { 1535 | var hash_head; /* head of hash chain */ 1536 | var bflush; /* set if current block must be flushed */ 1537 | 1538 | var max_insert; 1539 | 1540 | /* Process the input block. */ 1541 | for (;;) { 1542 | /* Make sure that we always have enough lookahead, except 1543 | * at the end of the input file. We need MAX_MATCH bytes 1544 | * for the next match, plus MIN_MATCH bytes to insert the 1545 | * string following the next match. 1546 | */ 1547 | if (s.lookahead < MIN_LOOKAHEAD) { 1548 | fill_window(s); 1549 | if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { 1550 | return BS_NEED_MORE; 1551 | } 1552 | if (s.lookahead === 0) { break; } /* flush the current block */ 1553 | } 1554 | 1555 | /* Insert the string window[strstart .. strstart+2] in the 1556 | * dictionary, and set hash_head to the head of the hash chain: 1557 | */ 1558 | hash_head = 0/*NIL*/; 1559 | if (s.lookahead >= MIN_MATCH) { 1560 | /*** INSERT_STRING(s, s.strstart, hash_head); ***/ 1561 | s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; 1562 | hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; 1563 | s.head[s.ins_h] = s.strstart; 1564 | /***/ 1565 | } 1566 | 1567 | /* Find the longest match, discarding those <= prev_length. 1568 | */ 1569 | s.prev_length = s.match_length; 1570 | s.prev_match = s.match_start; 1571 | s.match_length = MIN_MATCH - 1; 1572 | 1573 | if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match && 1574 | s.strstart - hash_head <= (s.w_size - MIN_LOOKAHEAD)/*MAX_DIST(s)*/) { 1575 | /* To simplify the code, we prevent matches with the string 1576 | * of window index 0 (in particular we have to avoid a match 1577 | * of the string with itself at the start of the input file). 1578 | */ 1579 | s.match_length = longest_match(s, hash_head); 1580 | /* longest_match() sets match_start */ 1581 | 1582 | if (s.match_length <= 5 && 1583 | (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) { 1584 | 1585 | /* If prev_match is also MIN_MATCH, match_start is garbage 1586 | * but we will ignore the current match anyway. 1587 | */ 1588 | s.match_length = MIN_MATCH - 1; 1589 | } 1590 | } 1591 | /* If there was a match at the previous step and the current 1592 | * match is not better, output the previous match: 1593 | */ 1594 | if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) { 1595 | max_insert = s.strstart + s.lookahead - MIN_MATCH; 1596 | /* Do not insert strings in hash table beyond this. */ 1597 | 1598 | //check_match(s, s.strstart-1, s.prev_match, s.prev_length); 1599 | 1600 | /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match, 1601 | s.prev_length - MIN_MATCH, bflush);***/ 1602 | bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH); 1603 | /* Insert in hash table all strings up to the end of the match. 1604 | * strstart-1 and strstart are already inserted. If there is not 1605 | * enough lookahead, the last two strings are not inserted in 1606 | * the hash table. 1607 | */ 1608 | s.lookahead -= s.prev_length - 1; 1609 | s.prev_length -= 2; 1610 | do { 1611 | if (++s.strstart <= max_insert) { 1612 | /*** INSERT_STRING(s, s.strstart, hash_head); ***/ 1613 | s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; 1614 | hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; 1615 | s.head[s.ins_h] = s.strstart; 1616 | /***/ 1617 | } 1618 | } while (--s.prev_length !== 0); 1619 | s.match_available = 0; 1620 | s.match_length = MIN_MATCH - 1; 1621 | s.strstart++; 1622 | 1623 | if (bflush) { 1624 | /*** FLUSH_BLOCK(s, 0); ***/ 1625 | flush_block_only(s, false); 1626 | if (s.strm.avail_out === 0) { 1627 | return BS_NEED_MORE; 1628 | } 1629 | /***/ 1630 | } 1631 | 1632 | } else if (s.match_available) { 1633 | /* If there was no match at the previous position, output a 1634 | * single literal. If there was a match but the current match 1635 | * is longer, truncate the previous match to a single literal. 1636 | */ 1637 | //Tracevv((stderr,"%c", s->window[s->strstart-1])); 1638 | /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ 1639 | bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]); 1640 | 1641 | if (bflush) { 1642 | /*** FLUSH_BLOCK_ONLY(s, 0) ***/ 1643 | flush_block_only(s, false); 1644 | /***/ 1645 | } 1646 | s.strstart++; 1647 | s.lookahead--; 1648 | if (s.strm.avail_out === 0) { 1649 | return BS_NEED_MORE; 1650 | } 1651 | } else { 1652 | /* There is no previous match to compare with, wait for 1653 | * the next step to decide. 1654 | */ 1655 | s.match_available = 1; 1656 | s.strstart++; 1657 | s.lookahead--; 1658 | } 1659 | } 1660 | //Assert (flush != Z_NO_FLUSH, "no flush?"); 1661 | if (s.match_available) { 1662 | //Tracevv((stderr,"%c", s->window[s->strstart-1])); 1663 | /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ 1664 | bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]); 1665 | 1666 | s.match_available = 0; 1667 | } 1668 | s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1; 1669 | if (flush === Z_FINISH) { 1670 | /*** FLUSH_BLOCK(s, 1); ***/ 1671 | flush_block_only(s, true); 1672 | if (s.strm.avail_out === 0) { 1673 | return BS_FINISH_STARTED; 1674 | } 1675 | /***/ 1676 | return BS_FINISH_DONE; 1677 | } 1678 | if (s.last_lit) { 1679 | /*** FLUSH_BLOCK(s, 0); ***/ 1680 | flush_block_only(s, false); 1681 | if (s.strm.avail_out === 0) { 1682 | return BS_NEED_MORE; 1683 | } 1684 | /***/ 1685 | } 1686 | 1687 | return BS_BLOCK_DONE; 1688 | } 1689 | 1690 | 1691 | /* =========================================================================== 1692 | * For Z_RLE, simply look for runs of bytes, generate matches only of distance 1693 | * one. Do not maintain a hash table. (It will be regenerated if this run of 1694 | * deflate switches away from Z_RLE.) 1695 | */ 1696 | function deflate_rle(s, flush) { 1697 | var bflush; /* set if current block must be flushed */ 1698 | var prev; /* byte at distance one to match */ 1699 | var scan, strend; /* scan goes up to strend for length of run */ 1700 | 1701 | var _win = s.window; 1702 | 1703 | for (;;) { 1704 | /* Make sure that we always have enough lookahead, except 1705 | * at the end of the input file. We need MAX_MATCH bytes 1706 | * for the longest run, plus one for the unrolled loop. 1707 | */ 1708 | if (s.lookahead <= MAX_MATCH) { 1709 | fill_window(s); 1710 | if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) { 1711 | return BS_NEED_MORE; 1712 | } 1713 | if (s.lookahead === 0) { break; } /* flush the current block */ 1714 | } 1715 | 1716 | /* See how many times the previous byte repeats */ 1717 | s.match_length = 0; 1718 | if (s.lookahead >= MIN_MATCH && s.strstart > 0) { 1719 | scan = s.strstart - 1; 1720 | prev = _win[scan]; 1721 | if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) { 1722 | strend = s.strstart + MAX_MATCH; 1723 | do { 1724 | /*jshint noempty:false*/ 1725 | } while (prev === _win[++scan] && prev === _win[++scan] && 1726 | prev === _win[++scan] && prev === _win[++scan] && 1727 | prev === _win[++scan] && prev === _win[++scan] && 1728 | prev === _win[++scan] && prev === _win[++scan] && 1729 | scan < strend); 1730 | s.match_length = MAX_MATCH - (strend - scan); 1731 | if (s.match_length > s.lookahead) { 1732 | s.match_length = s.lookahead; 1733 | } 1734 | } 1735 | //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); 1736 | } 1737 | 1738 | /* Emit match if have run of MIN_MATCH or longer, else emit literal */ 1739 | if (s.match_length >= MIN_MATCH) { 1740 | //check_match(s, s.strstart, s.strstart - 1, s.match_length); 1741 | 1742 | /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/ 1743 | bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH); 1744 | 1745 | s.lookahead -= s.match_length; 1746 | s.strstart += s.match_length; 1747 | s.match_length = 0; 1748 | } else { 1749 | /* No match, output a literal byte */ 1750 | //Tracevv((stderr,"%c", s->window[s->strstart])); 1751 | /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ 1752 | bflush = trees._tr_tally(s, 0, s.window[s.strstart]); 1753 | 1754 | s.lookahead--; 1755 | s.strstart++; 1756 | } 1757 | if (bflush) { 1758 | /*** FLUSH_BLOCK(s, 0); ***/ 1759 | flush_block_only(s, false); 1760 | if (s.strm.avail_out === 0) { 1761 | return BS_NEED_MORE; 1762 | } 1763 | /***/ 1764 | } 1765 | } 1766 | s.insert = 0; 1767 | if (flush === Z_FINISH) { 1768 | /*** FLUSH_BLOCK(s, 1); ***/ 1769 | flush_block_only(s, true); 1770 | if (s.strm.avail_out === 0) { 1771 | return BS_FINISH_STARTED; 1772 | } 1773 | /***/ 1774 | return BS_FINISH_DONE; 1775 | } 1776 | if (s.last_lit) { 1777 | /*** FLUSH_BLOCK(s, 0); ***/ 1778 | flush_block_only(s, false); 1779 | if (s.strm.avail_out === 0) { 1780 | return BS_NEED_MORE; 1781 | } 1782 | /***/ 1783 | } 1784 | return BS_BLOCK_DONE; 1785 | } 1786 | 1787 | /* =========================================================================== 1788 | * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. 1789 | * (It will be regenerated if this run of deflate switches away from Huffman.) 1790 | */ 1791 | function deflate_huff(s, flush) { 1792 | var bflush; /* set if current block must be flushed */ 1793 | 1794 | for (;;) { 1795 | /* Make sure that we have a literal to write. */ 1796 | if (s.lookahead === 0) { 1797 | fill_window(s); 1798 | if (s.lookahead === 0) { 1799 | if (flush === Z_NO_FLUSH) { 1800 | return BS_NEED_MORE; 1801 | } 1802 | break; /* flush the current block */ 1803 | } 1804 | } 1805 | 1806 | /* Output a literal byte */ 1807 | s.match_length = 0; 1808 | //Tracevv((stderr,"%c", s->window[s->strstart])); 1809 | /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ 1810 | bflush = trees._tr_tally(s, 0, s.window[s.strstart]); 1811 | s.lookahead--; 1812 | s.strstart++; 1813 | if (bflush) { 1814 | /*** FLUSH_BLOCK(s, 0); ***/ 1815 | flush_block_only(s, false); 1816 | if (s.strm.avail_out === 0) { 1817 | return BS_NEED_MORE; 1818 | } 1819 | /***/ 1820 | } 1821 | } 1822 | s.insert = 0; 1823 | if (flush === Z_FINISH) { 1824 | /*** FLUSH_BLOCK(s, 1); ***/ 1825 | flush_block_only(s, true); 1826 | if (s.strm.avail_out === 0) { 1827 | return BS_FINISH_STARTED; 1828 | } 1829 | /***/ 1830 | return BS_FINISH_DONE; 1831 | } 1832 | if (s.last_lit) { 1833 | /*** FLUSH_BLOCK(s, 0); ***/ 1834 | flush_block_only(s, false); 1835 | if (s.strm.avail_out === 0) { 1836 | return BS_NEED_MORE; 1837 | } 1838 | /***/ 1839 | } 1840 | return BS_BLOCK_DONE; 1841 | } 1842 | 1843 | /* Values for max_lazy_match, good_match and max_chain_length, depending on 1844 | * the desired pack level (0..9). The values given below have been tuned to 1845 | * exclude worst case performance for pathological files. Better values may be 1846 | * found for specific files. 1847 | */ 1848 | function Config(good_length, max_lazy, nice_length, max_chain, func) { 1849 | this.good_length = good_length; 1850 | this.max_lazy = max_lazy; 1851 | this.nice_length = nice_length; 1852 | this.max_chain = max_chain; 1853 | this.func = func; 1854 | } 1855 | 1856 | var configuration_table; 1857 | 1858 | configuration_table = [ 1859 | /* good lazy nice chain */ 1860 | new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */ 1861 | new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */ 1862 | new Config(4, 5, 16, 8, deflate_fast), /* 2 */ 1863 | new Config(4, 6, 32, 32, deflate_fast), /* 3 */ 1864 | 1865 | new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */ 1866 | new Config(8, 16, 32, 32, deflate_slow), /* 5 */ 1867 | new Config(8, 16, 128, 128, deflate_slow), /* 6 */ 1868 | new Config(8, 32, 128, 256, deflate_slow), /* 7 */ 1869 | new Config(32, 128, 258, 1024, deflate_slow), /* 8 */ 1870 | new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */ 1871 | ]; 1872 | 1873 | 1874 | /* =========================================================================== 1875 | * Initialize the "longest match" routines for a new zlib stream 1876 | */ 1877 | function lm_init(s) { 1878 | s.window_size = 2 * s.w_size; 1879 | 1880 | /*** CLEAR_HASH(s); ***/ 1881 | zero(s.head); // Fill with NIL (= 0); 1882 | 1883 | /* Set the default configuration parameters: 1884 | */ 1885 | s.max_lazy_match = configuration_table[s.level].max_lazy; 1886 | s.good_match = configuration_table[s.level].good_length; 1887 | s.nice_match = configuration_table[s.level].nice_length; 1888 | s.max_chain_length = configuration_table[s.level].max_chain; 1889 | 1890 | s.strstart = 0; 1891 | s.block_start = 0; 1892 | s.lookahead = 0; 1893 | s.insert = 0; 1894 | s.match_length = s.prev_length = MIN_MATCH - 1; 1895 | s.match_available = 0; 1896 | s.ins_h = 0; 1897 | } 1898 | 1899 | 1900 | function DeflateState() { 1901 | this.strm = null; /* pointer back to this zlib stream */ 1902 | this.status = 0; /* as the name implies */ 1903 | this.pending_buf = null; /* output still pending */ 1904 | this.pending_buf_size = 0; /* size of pending_buf */ 1905 | this.pending_out = 0; /* next pending byte to output to the stream */ 1906 | this.pending = 0; /* nb of bytes in the pending buffer */ 1907 | this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ 1908 | this.gzhead = null; /* gzip header information to write */ 1909 | this.gzindex = 0; /* where in extra, name, or comment */ 1910 | this.method = Z_DEFLATED; /* can only be DEFLATED */ 1911 | this.last_flush = -1; /* value of flush param for previous deflate call */ 1912 | 1913 | this.w_size = 0; /* LZ77 window size (32K by default) */ 1914 | this.w_bits = 0; /* log2(w_size) (8..16) */ 1915 | this.w_mask = 0; /* w_size - 1 */ 1916 | 1917 | this.window = null; 1918 | /* Sliding window. Input bytes are read into the second half of the window, 1919 | * and move to the first half later to keep a dictionary of at least wSize 1920 | * bytes. With this organization, matches are limited to a distance of 1921 | * wSize-MAX_MATCH bytes, but this ensures that IO is always 1922 | * performed with a length multiple of the block size. 1923 | */ 1924 | 1925 | this.window_size = 0; 1926 | /* Actual size of window: 2*wSize, except when the user input buffer 1927 | * is directly used as sliding window. 1928 | */ 1929 | 1930 | this.prev = null; 1931 | /* Link to older string with same hash index. To limit the size of this 1932 | * array to 64K, this link is maintained only for the last 32K strings. 1933 | * An index in this array is thus a window index modulo 32K. 1934 | */ 1935 | 1936 | this.head = null; /* Heads of the hash chains or NIL. */ 1937 | 1938 | this.ins_h = 0; /* hash index of string to be inserted */ 1939 | this.hash_size = 0; /* number of elements in hash table */ 1940 | this.hash_bits = 0; /* log2(hash_size) */ 1941 | this.hash_mask = 0; /* hash_size-1 */ 1942 | 1943 | this.hash_shift = 0; 1944 | /* Number of bits by which ins_h must be shifted at each input 1945 | * step. It must be such that after MIN_MATCH steps, the oldest 1946 | * byte no longer takes part in the hash key, that is: 1947 | * hash_shift * MIN_MATCH >= hash_bits 1948 | */ 1949 | 1950 | this.block_start = 0; 1951 | /* Window position at the beginning of the current output block. Gets 1952 | * negative when the window is moved backwards. 1953 | */ 1954 | 1955 | this.match_length = 0; /* length of best match */ 1956 | this.prev_match = 0; /* previous match */ 1957 | this.match_available = 0; /* set if previous match exists */ 1958 | this.strstart = 0; /* start of string to insert */ 1959 | this.match_start = 0; /* start of matching string */ 1960 | this.lookahead = 0; /* number of valid bytes ahead in window */ 1961 | 1962 | this.prev_length = 0; 1963 | /* Length of the best match at previous step. Matches not greater than this 1964 | * are discarded. This is used in the lazy match evaluation. 1965 | */ 1966 | 1967 | this.max_chain_length = 0; 1968 | /* To speed up deflation, hash chains are never searched beyond this 1969 | * length. A higher limit improves compression ratio but degrades the 1970 | * speed. 1971 | */ 1972 | 1973 | this.max_lazy_match = 0; 1974 | /* Attempt to find a better match only when the current match is strictly 1975 | * smaller than this value. This mechanism is used only for compression 1976 | * levels >= 4. 1977 | */ 1978 | // That's alias to max_lazy_match, don't use directly 1979 | //this.max_insert_length = 0; 1980 | /* Insert new strings in the hash table only if the match length is not 1981 | * greater than this length. This saves time but degrades compression. 1982 | * max_insert_length is used only for compression levels <= 3. 1983 | */ 1984 | 1985 | this.level = 0; /* compression level (1..9) */ 1986 | this.strategy = 0; /* favor or force Huffman coding*/ 1987 | 1988 | this.good_match = 0; 1989 | /* Use a faster search when the previous match is longer than this */ 1990 | 1991 | this.nice_match = 0; /* Stop searching when current match exceeds this */ 1992 | 1993 | /* used by trees.c: */ 1994 | 1995 | /* Didn't use ct_data typedef below to suppress compiler warning */ 1996 | 1997 | // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ 1998 | // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ 1999 | // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ 2000 | 2001 | // Use flat array of DOUBLE size, with interleaved fata, 2002 | // because JS does not support effective 2003 | this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2); 2004 | this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2); 2005 | this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2); 2006 | zero(this.dyn_ltree); 2007 | zero(this.dyn_dtree); 2008 | zero(this.bl_tree); 2009 | 2010 | this.l_desc = null; /* desc. for literal tree */ 2011 | this.d_desc = null; /* desc. for distance tree */ 2012 | this.bl_desc = null; /* desc. for bit length tree */ 2013 | 2014 | //ush bl_count[MAX_BITS+1]; 2015 | this.bl_count = new utils.Buf16(MAX_BITS + 1); 2016 | /* number of codes at each bit length for an optimal tree */ 2017 | 2018 | //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ 2019 | this.heap = new utils.Buf16(2 * L_CODES + 1); /* heap used to build the Huffman trees */ 2020 | zero(this.heap); 2021 | 2022 | this.heap_len = 0; /* number of elements in the heap */ 2023 | this.heap_max = 0; /* element of largest frequency */ 2024 | /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. 2025 | * The same heap array is used to build all trees. 2026 | */ 2027 | 2028 | this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1]; 2029 | zero(this.depth); 2030 | /* Depth of each subtree used as tie breaker for trees of equal frequency 2031 | */ 2032 | 2033 | this.l_buf = 0; /* buffer index for literals or lengths */ 2034 | 2035 | this.lit_bufsize = 0; 2036 | /* Size of match buffer for literals/lengths. There are 4 reasons for 2037 | * limiting lit_bufsize to 64K: 2038 | * - frequencies can be kept in 16 bit counters 2039 | * - if compression is not successful for the first block, all input 2040 | * data is still in the window so we can still emit a stored block even 2041 | * when input comes from standard input. (This can also be done for 2042 | * all blocks if lit_bufsize is not greater than 32K.) 2043 | * - if compression is not successful for a file smaller than 64K, we can 2044 | * even emit a stored file instead of a stored block (saving 5 bytes). 2045 | * This is applicable only for zip (not gzip or zlib). 2046 | * - creating new Huffman trees less frequently may not provide fast 2047 | * adaptation to changes in the input data statistics. (Take for 2048 | * example a binary file with poorly compressible code followed by 2049 | * a highly compressible string table.) Smaller buffer sizes give 2050 | * fast adaptation but have of course the overhead of transmitting 2051 | * trees more frequently. 2052 | * - I can't count above 4 2053 | */ 2054 | 2055 | this.last_lit = 0; /* running index in l_buf */ 2056 | 2057 | this.d_buf = 0; 2058 | /* Buffer index for distances. To simplify the code, d_buf and l_buf have 2059 | * the same number of elements. To use different lengths, an extra flag 2060 | * array would be necessary. 2061 | */ 2062 | 2063 | this.opt_len = 0; /* bit length of current block with optimal trees */ 2064 | this.static_len = 0; /* bit length of current block with static trees */ 2065 | this.matches = 0; /* number of string matches in current block */ 2066 | this.insert = 0; /* bytes at end of window left to insert */ 2067 | 2068 | 2069 | this.bi_buf = 0; 2070 | /* Output buffer. bits are inserted starting at the bottom (least 2071 | * significant bits). 2072 | */ 2073 | this.bi_valid = 0; 2074 | /* Number of valid bits in bi_buf. All bits above the last valid bit 2075 | * are always zero. 2076 | */ 2077 | 2078 | // Used for window memory init. We safely ignore it for JS. That makes 2079 | // sense only for pointers and memory check tools. 2080 | //this.high_water = 0; 2081 | /* High water mark offset in window for initialized bytes -- bytes above 2082 | * this are set to zero in order to avoid memory check warnings when 2083 | * longest match routines access bytes past the input. This is then 2084 | * updated to the new high water mark. 2085 | */ 2086 | } 2087 | 2088 | 2089 | function deflateResetKeep(strm) { 2090 | var s; 2091 | 2092 | if (!strm || !strm.state) { 2093 | return err(strm, Z_STREAM_ERROR); 2094 | } 2095 | 2096 | strm.total_in = strm.total_out = 0; 2097 | strm.data_type = Z_UNKNOWN; 2098 | 2099 | s = strm.state; 2100 | s.pending = 0; 2101 | s.pending_out = 0; 2102 | 2103 | if (s.wrap < 0) { 2104 | s.wrap = -s.wrap; 2105 | /* was made negative by deflate(..., Z_FINISH); */ 2106 | } 2107 | s.status = (s.wrap ? INIT_STATE : BUSY_STATE); 2108 | strm.adler = (s.wrap === 2) ? 2109 | 0 // crc32(0, Z_NULL, 0) 2110 | : 2111 | 1; // adler32(0, Z_NULL, 0) 2112 | s.last_flush = Z_NO_FLUSH; 2113 | trees._tr_init(s); 2114 | return Z_OK; 2115 | } 2116 | 2117 | 2118 | function deflateReset(strm) { 2119 | var ret = deflateResetKeep(strm); 2120 | if (ret === Z_OK) { 2121 | lm_init(strm.state); 2122 | } 2123 | return ret; 2124 | } 2125 | 2126 | 2127 | function deflateSetHeader(strm, head) { 2128 | if (!strm || !strm.state) { return Z_STREAM_ERROR; } 2129 | if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; } 2130 | strm.state.gzhead = head; 2131 | return Z_OK; 2132 | } 2133 | 2134 | 2135 | function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { 2136 | if (!strm) { // === Z_NULL 2137 | return Z_STREAM_ERROR; 2138 | } 2139 | var wrap = 1; 2140 | 2141 | if (level === Z_DEFAULT_COMPRESSION) { 2142 | level = 6; 2143 | } 2144 | 2145 | if (windowBits < 0) { /* suppress zlib wrapper */ 2146 | wrap = 0; 2147 | windowBits = -windowBits; 2148 | } 2149 | 2150 | else if (windowBits > 15) { 2151 | wrap = 2; /* write gzip wrapper instead */ 2152 | windowBits -= 16; 2153 | } 2154 | 2155 | 2156 | if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || 2157 | windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || 2158 | strategy < 0 || strategy > Z_FIXED) { 2159 | return err(strm, Z_STREAM_ERROR); 2160 | } 2161 | 2162 | 2163 | if (windowBits === 8) { 2164 | windowBits = 9; 2165 | } 2166 | /* until 256-byte window bug fixed */ 2167 | 2168 | var s = new DeflateState(); 2169 | 2170 | strm.state = s; 2171 | s.strm = strm; 2172 | 2173 | s.wrap = wrap; 2174 | s.gzhead = null; 2175 | s.w_bits = windowBits; 2176 | s.w_size = 1 << s.w_bits; 2177 | s.w_mask = s.w_size - 1; 2178 | 2179 | s.hash_bits = memLevel + 7; 2180 | s.hash_size = 1 << s.hash_bits; 2181 | s.hash_mask = s.hash_size - 1; 2182 | s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH); 2183 | 2184 | s.window = new utils.Buf8(s.w_size * 2); 2185 | s.head = new utils.Buf16(s.hash_size); 2186 | s.prev = new utils.Buf16(s.w_size); 2187 | 2188 | // Don't need mem init magic for JS. 2189 | //s.high_water = 0; /* nothing written to s->window yet */ 2190 | 2191 | s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ 2192 | 2193 | s.pending_buf_size = s.lit_bufsize * 4; 2194 | 2195 | //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); 2196 | //s->pending_buf = (uchf *) overlay; 2197 | s.pending_buf = new utils.Buf8(s.pending_buf_size); 2198 | 2199 | // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`) 2200 | //s->d_buf = overlay + s->lit_bufsize/sizeof(ush); 2201 | s.d_buf = 1 * s.lit_bufsize; 2202 | 2203 | //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; 2204 | s.l_buf = (1 + 2) * s.lit_bufsize; 2205 | 2206 | s.level = level; 2207 | s.strategy = strategy; 2208 | s.method = method; 2209 | 2210 | return deflateReset(strm); 2211 | } 2212 | 2213 | function deflateInit(strm, level) { 2214 | return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); 2215 | } 2216 | 2217 | 2218 | function deflate(strm, flush) { 2219 | var old_flush, s; 2220 | var beg, val; // for gzip header write only 2221 | 2222 | if (!strm || !strm.state || 2223 | flush > Z_BLOCK || flush < 0) { 2224 | return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR; 2225 | } 2226 | 2227 | s = strm.state; 2228 | 2229 | if (!strm.output || 2230 | (!strm.input && strm.avail_in !== 0) || 2231 | (s.status === FINISH_STATE && flush !== Z_FINISH)) { 2232 | return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR); 2233 | } 2234 | 2235 | s.strm = strm; /* just in case */ 2236 | old_flush = s.last_flush; 2237 | s.last_flush = flush; 2238 | 2239 | /* Write the header */ 2240 | if (s.status === INIT_STATE) { 2241 | 2242 | if (s.wrap === 2) { // GZIP header 2243 | strm.adler = 0; //crc32(0L, Z_NULL, 0); 2244 | put_byte(s, 31); 2245 | put_byte(s, 139); 2246 | put_byte(s, 8); 2247 | if (!s.gzhead) { // s->gzhead == Z_NULL 2248 | put_byte(s, 0); 2249 | put_byte(s, 0); 2250 | put_byte(s, 0); 2251 | put_byte(s, 0); 2252 | put_byte(s, 0); 2253 | put_byte(s, s.level === 9 ? 2 : 2254 | (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 2255 | 4 : 0)); 2256 | put_byte(s, OS_CODE); 2257 | s.status = BUSY_STATE; 2258 | } 2259 | else { 2260 | put_byte(s, (s.gzhead.text ? 1 : 0) + 2261 | (s.gzhead.hcrc ? 2 : 0) + 2262 | (!s.gzhead.extra ? 0 : 4) + 2263 | (!s.gzhead.name ? 0 : 8) + 2264 | (!s.gzhead.comment ? 0 : 16) 2265 | ); 2266 | put_byte(s, s.gzhead.time & 0xff); 2267 | put_byte(s, (s.gzhead.time >> 8) & 0xff); 2268 | put_byte(s, (s.gzhead.time >> 16) & 0xff); 2269 | put_byte(s, (s.gzhead.time >> 24) & 0xff); 2270 | put_byte(s, s.level === 9 ? 2 : 2271 | (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 2272 | 4 : 0)); 2273 | put_byte(s, s.gzhead.os & 0xff); 2274 | if (s.gzhead.extra && s.gzhead.extra.length) { 2275 | put_byte(s, s.gzhead.extra.length & 0xff); 2276 | put_byte(s, (s.gzhead.extra.length >> 8) & 0xff); 2277 | } 2278 | if (s.gzhead.hcrc) { 2279 | strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0); 2280 | } 2281 | s.gzindex = 0; 2282 | s.status = EXTRA_STATE; 2283 | } 2284 | } 2285 | else // DEFLATE header 2286 | { 2287 | var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8; 2288 | var level_flags = -1; 2289 | 2290 | if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) { 2291 | level_flags = 0; 2292 | } else if (s.level < 6) { 2293 | level_flags = 1; 2294 | } else if (s.level === 6) { 2295 | level_flags = 2; 2296 | } else { 2297 | level_flags = 3; 2298 | } 2299 | header |= (level_flags << 6); 2300 | if (s.strstart !== 0) { header |= PRESET_DICT; } 2301 | header += 31 - (header % 31); 2302 | 2303 | s.status = BUSY_STATE; 2304 | putShortMSB(s, header); 2305 | 2306 | /* Save the adler32 of the preset dictionary: */ 2307 | if (s.strstart !== 0) { 2308 | putShortMSB(s, strm.adler >>> 16); 2309 | putShortMSB(s, strm.adler & 0xffff); 2310 | } 2311 | strm.adler = 1; // adler32(0L, Z_NULL, 0); 2312 | } 2313 | } 2314 | 2315 | //#ifdef GZIP 2316 | if (s.status === EXTRA_STATE) { 2317 | if (s.gzhead.extra/* != Z_NULL*/) { 2318 | beg = s.pending; /* start of bytes to update crc */ 2319 | 2320 | while (s.gzindex < (s.gzhead.extra.length & 0xffff)) { 2321 | if (s.pending === s.pending_buf_size) { 2322 | if (s.gzhead.hcrc && s.pending > beg) { 2323 | strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); 2324 | } 2325 | flush_pending(strm); 2326 | beg = s.pending; 2327 | if (s.pending === s.pending_buf_size) { 2328 | break; 2329 | } 2330 | } 2331 | put_byte(s, s.gzhead.extra[s.gzindex] & 0xff); 2332 | s.gzindex++; 2333 | } 2334 | if (s.gzhead.hcrc && s.pending > beg) { 2335 | strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); 2336 | } 2337 | if (s.gzindex === s.gzhead.extra.length) { 2338 | s.gzindex = 0; 2339 | s.status = NAME_STATE; 2340 | } 2341 | } 2342 | else { 2343 | s.status = NAME_STATE; 2344 | } 2345 | } 2346 | if (s.status === NAME_STATE) { 2347 | if (s.gzhead.name/* != Z_NULL*/) { 2348 | beg = s.pending; /* start of bytes to update crc */ 2349 | //int val; 2350 | 2351 | do { 2352 | if (s.pending === s.pending_buf_size) { 2353 | if (s.gzhead.hcrc && s.pending > beg) { 2354 | strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); 2355 | } 2356 | flush_pending(strm); 2357 | beg = s.pending; 2358 | if (s.pending === s.pending_buf_size) { 2359 | val = 1; 2360 | break; 2361 | } 2362 | } 2363 | // JS specific: little magic to add zero terminator to end of string 2364 | if (s.gzindex < s.gzhead.name.length) { 2365 | val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff; 2366 | } else { 2367 | val = 0; 2368 | } 2369 | put_byte(s, val); 2370 | } while (val !== 0); 2371 | 2372 | if (s.gzhead.hcrc && s.pending > beg) { 2373 | strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); 2374 | } 2375 | if (val === 0) { 2376 | s.gzindex = 0; 2377 | s.status = COMMENT_STATE; 2378 | } 2379 | } 2380 | else { 2381 | s.status = COMMENT_STATE; 2382 | } 2383 | } 2384 | if (s.status === COMMENT_STATE) { 2385 | if (s.gzhead.comment/* != Z_NULL*/) { 2386 | beg = s.pending; /* start of bytes to update crc */ 2387 | //int val; 2388 | 2389 | do { 2390 | if (s.pending === s.pending_buf_size) { 2391 | if (s.gzhead.hcrc && s.pending > beg) { 2392 | strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); 2393 | } 2394 | flush_pending(strm); 2395 | beg = s.pending; 2396 | if (s.pending === s.pending_buf_size) { 2397 | val = 1; 2398 | break; 2399 | } 2400 | } 2401 | // JS specific: little magic to add zero terminator to end of string 2402 | if (s.gzindex < s.gzhead.comment.length) { 2403 | val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff; 2404 | } else { 2405 | val = 0; 2406 | } 2407 | put_byte(s, val); 2408 | } while (val !== 0); 2409 | 2410 | if (s.gzhead.hcrc && s.pending > beg) { 2411 | strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); 2412 | } 2413 | if (val === 0) { 2414 | s.status = HCRC_STATE; 2415 | } 2416 | } 2417 | else { 2418 | s.status = HCRC_STATE; 2419 | } 2420 | } 2421 | if (s.status === HCRC_STATE) { 2422 | if (s.gzhead.hcrc) { 2423 | if (s.pending + 2 > s.pending_buf_size) { 2424 | flush_pending(strm); 2425 | } 2426 | if (s.pending + 2 <= s.pending_buf_size) { 2427 | put_byte(s, strm.adler & 0xff); 2428 | put_byte(s, (strm.adler >> 8) & 0xff); 2429 | strm.adler = 0; //crc32(0L, Z_NULL, 0); 2430 | s.status = BUSY_STATE; 2431 | } 2432 | } 2433 | else { 2434 | s.status = BUSY_STATE; 2435 | } 2436 | } 2437 | //#endif 2438 | 2439 | /* Flush as much pending output as possible */ 2440 | if (s.pending !== 0) { 2441 | flush_pending(strm); 2442 | if (strm.avail_out === 0) { 2443 | /* Since avail_out is 0, deflate will be called again with 2444 | * more output space, but possibly with both pending and 2445 | * avail_in equal to zero. There won't be anything to do, 2446 | * but this is not an error situation so make sure we 2447 | * return OK instead of BUF_ERROR at next call of deflate: 2448 | */ 2449 | s.last_flush = -1; 2450 | return Z_OK; 2451 | } 2452 | 2453 | /* Make sure there is something to do and avoid duplicate consecutive 2454 | * flushes. For repeated and useless calls with Z_FINISH, we keep 2455 | * returning Z_STREAM_END instead of Z_BUF_ERROR. 2456 | */ 2457 | } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && 2458 | flush !== Z_FINISH) { 2459 | return err(strm, Z_BUF_ERROR); 2460 | } 2461 | 2462 | /* User must not provide more input after the first FINISH: */ 2463 | if (s.status === FINISH_STATE && strm.avail_in !== 0) { 2464 | return err(strm, Z_BUF_ERROR); 2465 | } 2466 | 2467 | /* Start a new block or continue the current one. 2468 | */ 2469 | if (strm.avail_in !== 0 || s.lookahead !== 0 || 2470 | (flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) { 2471 | var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) : 2472 | (s.strategy === Z_RLE ? deflate_rle(s, flush) : 2473 | configuration_table[s.level].func(s, flush)); 2474 | 2475 | if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) { 2476 | s.status = FINISH_STATE; 2477 | } 2478 | if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) { 2479 | if (strm.avail_out === 0) { 2480 | s.last_flush = -1; 2481 | /* avoid BUF_ERROR next call, see above */ 2482 | } 2483 | return Z_OK; 2484 | /* If flush != Z_NO_FLUSH && avail_out == 0, the next call 2485 | * of deflate should use the same flush parameter to make sure 2486 | * that the flush is complete. So we don't have to output an 2487 | * empty block here, this will be done at next call. This also 2488 | * ensures that for a very small output buffer, we emit at most 2489 | * one empty block. 2490 | */ 2491 | } 2492 | if (bstate === BS_BLOCK_DONE) { 2493 | if (flush === Z_PARTIAL_FLUSH) { 2494 | trees._tr_align(s); 2495 | } 2496 | else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ 2497 | 2498 | trees._tr_stored_block(s, 0, 0, false); 2499 | /* For a full flush, this empty block will be recognized 2500 | * as a special marker by inflate_sync(). 2501 | */ 2502 | if (flush === Z_FULL_FLUSH) { 2503 | /*** CLEAR_HASH(s); ***/ /* forget history */ 2504 | zero(s.head); // Fill with NIL (= 0); 2505 | 2506 | if (s.lookahead === 0) { 2507 | s.strstart = 0; 2508 | s.block_start = 0; 2509 | s.insert = 0; 2510 | } 2511 | } 2512 | } 2513 | flush_pending(strm); 2514 | if (strm.avail_out === 0) { 2515 | s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */ 2516 | return Z_OK; 2517 | } 2518 | } 2519 | } 2520 | //Assert(strm->avail_out > 0, "bug2"); 2521 | //if (strm.avail_out <= 0) { throw new Error("bug2");} 2522 | 2523 | if (flush !== Z_FINISH) { return Z_OK; } 2524 | if (s.wrap <= 0) { return Z_STREAM_END; } 2525 | 2526 | /* Write the trailer */ 2527 | if (s.wrap === 2) { 2528 | put_byte(s, strm.adler & 0xff); 2529 | put_byte(s, (strm.adler >> 8) & 0xff); 2530 | put_byte(s, (strm.adler >> 16) & 0xff); 2531 | put_byte(s, (strm.adler >> 24) & 0xff); 2532 | put_byte(s, strm.total_in & 0xff); 2533 | put_byte(s, (strm.total_in >> 8) & 0xff); 2534 | put_byte(s, (strm.total_in >> 16) & 0xff); 2535 | put_byte(s, (strm.total_in >> 24) & 0xff); 2536 | } 2537 | else 2538 | { 2539 | putShortMSB(s, strm.adler >>> 16); 2540 | putShortMSB(s, strm.adler & 0xffff); 2541 | } 2542 | 2543 | flush_pending(strm); 2544 | /* If avail_out is zero, the application will call deflate again 2545 | * to flush the rest. 2546 | */ 2547 | if (s.wrap > 0) { s.wrap = -s.wrap; } 2548 | /* write the trailer only once! */ 2549 | return s.pending !== 0 ? Z_OK : Z_STREAM_END; 2550 | } 2551 | 2552 | function deflateEnd(strm) { 2553 | var status; 2554 | 2555 | if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) { 2556 | return Z_STREAM_ERROR; 2557 | } 2558 | 2559 | status = strm.state.status; 2560 | if (status !== INIT_STATE && 2561 | status !== EXTRA_STATE && 2562 | status !== NAME_STATE && 2563 | status !== COMMENT_STATE && 2564 | status !== HCRC_STATE && 2565 | status !== BUSY_STATE && 2566 | status !== FINISH_STATE 2567 | ) { 2568 | return err(strm, Z_STREAM_ERROR); 2569 | } 2570 | 2571 | strm.state = null; 2572 | 2573 | return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK; 2574 | } 2575 | 2576 | 2577 | /* ========================================================================= 2578 | * Initializes the compression dictionary from the given byte 2579 | * sequence without producing any compressed output. 2580 | */ 2581 | function deflateSetDictionary(strm, dictionary) { 2582 | var dictLength = dictionary.length; 2583 | 2584 | var s; 2585 | var str, n; 2586 | var wrap; 2587 | var avail; 2588 | var next; 2589 | var input; 2590 | var tmpDict; 2591 | 2592 | if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) { 2593 | return Z_STREAM_ERROR; 2594 | } 2595 | 2596 | s = strm.state; 2597 | wrap = s.wrap; 2598 | 2599 | if (wrap === 2 || (wrap === 1 && s.status !== INIT_STATE) || s.lookahead) { 2600 | return Z_STREAM_ERROR; 2601 | } 2602 | 2603 | /* when using zlib wrappers, compute Adler-32 for provided dictionary */ 2604 | if (wrap === 1) { 2605 | /* adler32(strm->adler, dictionary, dictLength); */ 2606 | strm.adler = adler32(strm.adler, dictionary, dictLength, 0); 2607 | } 2608 | 2609 | s.wrap = 0; /* avoid computing Adler-32 in read_buf */ 2610 | 2611 | /* if dictionary would fill window, just replace the history */ 2612 | if (dictLength >= s.w_size) { 2613 | if (wrap === 0) { /* already empty otherwise */ 2614 | /*** CLEAR_HASH(s); ***/ 2615 | zero(s.head); // Fill with NIL (= 0); 2616 | s.strstart = 0; 2617 | s.block_start = 0; 2618 | s.insert = 0; 2619 | } 2620 | /* use the tail */ 2621 | // dictionary = dictionary.slice(dictLength - s.w_size); 2622 | tmpDict = new utils.Buf8(s.w_size); 2623 | utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0); 2624 | dictionary = tmpDict; 2625 | dictLength = s.w_size; 2626 | } 2627 | /* insert dictionary into window and hash */ 2628 | avail = strm.avail_in; 2629 | next = strm.next_in; 2630 | input = strm.input; 2631 | strm.avail_in = dictLength; 2632 | strm.next_in = 0; 2633 | strm.input = dictionary; 2634 | fill_window(s); 2635 | while (s.lookahead >= MIN_MATCH) { 2636 | str = s.strstart; 2637 | n = s.lookahead - (MIN_MATCH - 1); 2638 | do { 2639 | /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */ 2640 | s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask; 2641 | 2642 | s.prev[str & s.w_mask] = s.head[s.ins_h]; 2643 | 2644 | s.head[s.ins_h] = str; 2645 | str++; 2646 | } while (--n); 2647 | s.strstart = str; 2648 | s.lookahead = MIN_MATCH - 1; 2649 | fill_window(s); 2650 | } 2651 | s.strstart += s.lookahead; 2652 | s.block_start = s.strstart; 2653 | s.insert = s.lookahead; 2654 | s.lookahead = 0; 2655 | s.match_length = s.prev_length = MIN_MATCH - 1; 2656 | s.match_available = 0; 2657 | strm.next_in = next; 2658 | strm.input = input; 2659 | strm.avail_in = avail; 2660 | s.wrap = wrap; 2661 | return Z_OK; 2662 | } 2663 | 2664 | 2665 | exports.deflateInit = deflateInit; 2666 | exports.deflateInit2 = deflateInit2; 2667 | exports.deflateReset = deflateReset; 2668 | exports.deflateResetKeep = deflateResetKeep; 2669 | exports.deflateSetHeader = deflateSetHeader; 2670 | exports.deflate = deflate; 2671 | exports.deflateEnd = deflateEnd; 2672 | exports.deflateSetDictionary = deflateSetDictionary; 2673 | exports.deflateInfo = 'pako deflate (from Nodeca project)'; 2674 | 2675 | /* Not implemented 2676 | exports.deflateBound = deflateBound; 2677 | exports.deflateCopy = deflateCopy; 2678 | exports.deflateParams = deflateParams; 2679 | exports.deflatePending = deflatePending; 2680 | exports.deflatePrime = deflatePrime; 2681 | exports.deflateTune = deflateTune; 2682 | */ 2683 | 2684 | },{"../utils/common":2,"./adler32":4,"./crc32":5,"./messages":7,"./trees":8}],7:[function(require,module,exports){ 2685 | 'use strict'; 2686 | 2687 | // (C) 1995-2013 Jean-loup Gailly and Mark Adler 2688 | // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin 2689 | // 2690 | // This software is provided 'as-is', without any express or implied 2691 | // warranty. In no event will the authors be held liable for any damages 2692 | // arising from the use of this software. 2693 | // 2694 | // Permission is granted to anyone to use this software for any purpose, 2695 | // including commercial applications, and to alter it and redistribute it 2696 | // freely, subject to the following restrictions: 2697 | // 2698 | // 1. The origin of this software must not be misrepresented; you must not 2699 | // claim that you wrote the original software. If you use this software 2700 | // in a product, an acknowledgment in the product documentation would be 2701 | // appreciated but is not required. 2702 | // 2. Altered source versions must be plainly marked as such, and must not be 2703 | // misrepresented as being the original software. 2704 | // 3. This notice may not be removed or altered from any source distribution. 2705 | 2706 | module.exports = { 2707 | 2: 'need dictionary', /* Z_NEED_DICT 2 */ 2708 | 1: 'stream end', /* Z_STREAM_END 1 */ 2709 | 0: '', /* Z_OK 0 */ 2710 | '-1': 'file error', /* Z_ERRNO (-1) */ 2711 | '-2': 'stream error', /* Z_STREAM_ERROR (-2) */ 2712 | '-3': 'data error', /* Z_DATA_ERROR (-3) */ 2713 | '-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */ 2714 | '-5': 'buffer error', /* Z_BUF_ERROR (-5) */ 2715 | '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */ 2716 | }; 2717 | 2718 | },{}],8:[function(require,module,exports){ 2719 | 'use strict'; 2720 | 2721 | // (C) 1995-2013 Jean-loup Gailly and Mark Adler 2722 | // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin 2723 | // 2724 | // This software is provided 'as-is', without any express or implied 2725 | // warranty. In no event will the authors be held liable for any damages 2726 | // arising from the use of this software. 2727 | // 2728 | // Permission is granted to anyone to use this software for any purpose, 2729 | // including commercial applications, and to alter it and redistribute it 2730 | // freely, subject to the following restrictions: 2731 | // 2732 | // 1. The origin of this software must not be misrepresented; you must not 2733 | // claim that you wrote the original software. If you use this software 2734 | // in a product, an acknowledgment in the product documentation would be 2735 | // appreciated but is not required. 2736 | // 2. Altered source versions must be plainly marked as such, and must not be 2737 | // misrepresented as being the original software. 2738 | // 3. This notice may not be removed or altered from any source distribution. 2739 | 2740 | var utils = require('../utils/common'); 2741 | 2742 | /* Public constants ==========================================================*/ 2743 | /* ===========================================================================*/ 2744 | 2745 | 2746 | //var Z_FILTERED = 1; 2747 | //var Z_HUFFMAN_ONLY = 2; 2748 | //var Z_RLE = 3; 2749 | var Z_FIXED = 4; 2750 | //var Z_DEFAULT_STRATEGY = 0; 2751 | 2752 | /* Possible values of the data_type field (though see inflate()) */ 2753 | var Z_BINARY = 0; 2754 | var Z_TEXT = 1; 2755 | //var Z_ASCII = 1; // = Z_TEXT 2756 | var Z_UNKNOWN = 2; 2757 | 2758 | /*============================================================================*/ 2759 | 2760 | 2761 | function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } } 2762 | 2763 | // From zutil.h 2764 | 2765 | var STORED_BLOCK = 0; 2766 | var STATIC_TREES = 1; 2767 | var DYN_TREES = 2; 2768 | /* The three kinds of block type */ 2769 | 2770 | var MIN_MATCH = 3; 2771 | var MAX_MATCH = 258; 2772 | /* The minimum and maximum match lengths */ 2773 | 2774 | // From deflate.h 2775 | /* =========================================================================== 2776 | * Internal compression state. 2777 | */ 2778 | 2779 | var LENGTH_CODES = 29; 2780 | /* number of length codes, not counting the special END_BLOCK code */ 2781 | 2782 | var LITERALS = 256; 2783 | /* number of literal bytes 0..255 */ 2784 | 2785 | var L_CODES = LITERALS + 1 + LENGTH_CODES; 2786 | /* number of Literal or Length codes, including the END_BLOCK code */ 2787 | 2788 | var D_CODES = 30; 2789 | /* number of distance codes */ 2790 | 2791 | var BL_CODES = 19; 2792 | /* number of codes used to transfer the bit lengths */ 2793 | 2794 | var HEAP_SIZE = 2 * L_CODES + 1; 2795 | /* maximum heap size */ 2796 | 2797 | var MAX_BITS = 15; 2798 | /* All codes must not exceed MAX_BITS bits */ 2799 | 2800 | var Buf_size = 16; 2801 | /* size of bit buffer in bi_buf */ 2802 | 2803 | 2804 | /* =========================================================================== 2805 | * Constants 2806 | */ 2807 | 2808 | var MAX_BL_BITS = 7; 2809 | /* Bit length codes must not exceed MAX_BL_BITS bits */ 2810 | 2811 | var END_BLOCK = 256; 2812 | /* end of block literal code */ 2813 | 2814 | var REP_3_6 = 16; 2815 | /* repeat previous bit length 3-6 times (2 bits of repeat count) */ 2816 | 2817 | var REPZ_3_10 = 17; 2818 | /* repeat a zero length 3-10 times (3 bits of repeat count) */ 2819 | 2820 | var REPZ_11_138 = 18; 2821 | /* repeat a zero length 11-138 times (7 bits of repeat count) */ 2822 | 2823 | /* eslint-disable comma-spacing,array-bracket-spacing */ 2824 | var extra_lbits = /* extra bits for each length code */ 2825 | [0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]; 2826 | 2827 | var extra_dbits = /* extra bits for each distance code */ 2828 | [0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]; 2829 | 2830 | var extra_blbits = /* extra bits for each bit length code */ 2831 | [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]; 2832 | 2833 | var bl_order = 2834 | [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]; 2835 | /* eslint-enable comma-spacing,array-bracket-spacing */ 2836 | 2837 | /* The lengths of the bit length codes are sent in order of decreasing 2838 | * probability, to avoid transmitting the lengths for unused bit length codes. 2839 | */ 2840 | 2841 | /* =========================================================================== 2842 | * Local data. These are initialized only once. 2843 | */ 2844 | 2845 | // We pre-fill arrays with 0 to avoid uninitialized gaps 2846 | 2847 | var DIST_CODE_LEN = 512; /* see definition of array dist_code below */ 2848 | 2849 | // !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1 2850 | var static_ltree = new Array((L_CODES + 2) * 2); 2851 | zero(static_ltree); 2852 | /* The static literal tree. Since the bit lengths are imposed, there is no 2853 | * need for the L_CODES extra codes used during heap construction. However 2854 | * The codes 286 and 287 are needed to build a canonical tree (see _tr_init 2855 | * below). 2856 | */ 2857 | 2858 | var static_dtree = new Array(D_CODES * 2); 2859 | zero(static_dtree); 2860 | /* The static distance tree. (Actually a trivial tree since all codes use 2861 | * 5 bits.) 2862 | */ 2863 | 2864 | var _dist_code = new Array(DIST_CODE_LEN); 2865 | zero(_dist_code); 2866 | /* Distance codes. The first 256 values correspond to the distances 2867 | * 3 .. 258, the last 256 values correspond to the top 8 bits of 2868 | * the 15 bit distances. 2869 | */ 2870 | 2871 | var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1); 2872 | zero(_length_code); 2873 | /* length code for each normalized match length (0 == MIN_MATCH) */ 2874 | 2875 | var base_length = new Array(LENGTH_CODES); 2876 | zero(base_length); 2877 | /* First normalized length for each code (0 = MIN_MATCH) */ 2878 | 2879 | var base_dist = new Array(D_CODES); 2880 | zero(base_dist); 2881 | /* First normalized distance for each code (0 = distance of 1) */ 2882 | 2883 | 2884 | function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) { 2885 | 2886 | this.static_tree = static_tree; /* static tree or NULL */ 2887 | this.extra_bits = extra_bits; /* extra bits for each code or NULL */ 2888 | this.extra_base = extra_base; /* base index for extra_bits */ 2889 | this.elems = elems; /* max number of elements in the tree */ 2890 | this.max_length = max_length; /* max bit length for the codes */ 2891 | 2892 | // show if `static_tree` has data or dummy - needed for monomorphic objects 2893 | this.has_stree = static_tree && static_tree.length; 2894 | } 2895 | 2896 | 2897 | var static_l_desc; 2898 | var static_d_desc; 2899 | var static_bl_desc; 2900 | 2901 | 2902 | function TreeDesc(dyn_tree, stat_desc) { 2903 | this.dyn_tree = dyn_tree; /* the dynamic tree */ 2904 | this.max_code = 0; /* largest code with non zero frequency */ 2905 | this.stat_desc = stat_desc; /* the corresponding static tree */ 2906 | } 2907 | 2908 | 2909 | 2910 | function d_code(dist) { 2911 | return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)]; 2912 | } 2913 | 2914 | 2915 | /* =========================================================================== 2916 | * Output a short LSB first on the stream. 2917 | * IN assertion: there is enough room in pendingBuf. 2918 | */ 2919 | function put_short(s, w) { 2920 | // put_byte(s, (uch)((w) & 0xff)); 2921 | // put_byte(s, (uch)((ush)(w) >> 8)); 2922 | s.pending_buf[s.pending++] = (w) & 0xff; 2923 | s.pending_buf[s.pending++] = (w >>> 8) & 0xff; 2924 | } 2925 | 2926 | 2927 | /* =========================================================================== 2928 | * Send a value on a given number of bits. 2929 | * IN assertion: length <= 16 and value fits in length bits. 2930 | */ 2931 | function send_bits(s, value, length) { 2932 | if (s.bi_valid > (Buf_size - length)) { 2933 | s.bi_buf |= (value << s.bi_valid) & 0xffff; 2934 | put_short(s, s.bi_buf); 2935 | s.bi_buf = value >> (Buf_size - s.bi_valid); 2936 | s.bi_valid += length - Buf_size; 2937 | } else { 2938 | s.bi_buf |= (value << s.bi_valid) & 0xffff; 2939 | s.bi_valid += length; 2940 | } 2941 | } 2942 | 2943 | 2944 | function send_code(s, c, tree) { 2945 | send_bits(s, tree[c * 2]/*.Code*/, tree[c * 2 + 1]/*.Len*/); 2946 | } 2947 | 2948 | 2949 | /* =========================================================================== 2950 | * Reverse the first len bits of a code, using straightforward code (a faster 2951 | * method would use a table) 2952 | * IN assertion: 1 <= len <= 15 2953 | */ 2954 | function bi_reverse(code, len) { 2955 | var res = 0; 2956 | do { 2957 | res |= code & 1; 2958 | code >>>= 1; 2959 | res <<= 1; 2960 | } while (--len > 0); 2961 | return res >>> 1; 2962 | } 2963 | 2964 | 2965 | /* =========================================================================== 2966 | * Flush the bit buffer, keeping at most 7 bits in it. 2967 | */ 2968 | function bi_flush(s) { 2969 | if (s.bi_valid === 16) { 2970 | put_short(s, s.bi_buf); 2971 | s.bi_buf = 0; 2972 | s.bi_valid = 0; 2973 | 2974 | } else if (s.bi_valid >= 8) { 2975 | s.pending_buf[s.pending++] = s.bi_buf & 0xff; 2976 | s.bi_buf >>= 8; 2977 | s.bi_valid -= 8; 2978 | } 2979 | } 2980 | 2981 | 2982 | /* =========================================================================== 2983 | * Compute the optimal bit lengths for a tree and update the total bit length 2984 | * for the current block. 2985 | * IN assertion: the fields freq and dad are set, heap[heap_max] and 2986 | * above are the tree nodes sorted by increasing frequency. 2987 | * OUT assertions: the field len is set to the optimal bit length, the 2988 | * array bl_count contains the frequencies for each bit length. 2989 | * The length opt_len is updated; static_len is also updated if stree is 2990 | * not null. 2991 | */ 2992 | function gen_bitlen(s, desc) 2993 | // deflate_state *s; 2994 | // tree_desc *desc; /* the tree descriptor */ 2995 | { 2996 | var tree = desc.dyn_tree; 2997 | var max_code = desc.max_code; 2998 | var stree = desc.stat_desc.static_tree; 2999 | var has_stree = desc.stat_desc.has_stree; 3000 | var extra = desc.stat_desc.extra_bits; 3001 | var base = desc.stat_desc.extra_base; 3002 | var max_length = desc.stat_desc.max_length; 3003 | var h; /* heap index */ 3004 | var n, m; /* iterate over the tree elements */ 3005 | var bits; /* bit length */ 3006 | var xbits; /* extra bits */ 3007 | var f; /* frequency */ 3008 | var overflow = 0; /* number of elements with bit length too large */ 3009 | 3010 | for (bits = 0; bits <= MAX_BITS; bits++) { 3011 | s.bl_count[bits] = 0; 3012 | } 3013 | 3014 | /* In a first pass, compute the optimal bit lengths (which may 3015 | * overflow in the case of the bit length tree). 3016 | */ 3017 | tree[s.heap[s.heap_max] * 2 + 1]/*.Len*/ = 0; /* root of the heap */ 3018 | 3019 | for (h = s.heap_max + 1; h < HEAP_SIZE; h++) { 3020 | n = s.heap[h]; 3021 | bits = tree[tree[n * 2 + 1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1; 3022 | if (bits > max_length) { 3023 | bits = max_length; 3024 | overflow++; 3025 | } 3026 | tree[n * 2 + 1]/*.Len*/ = bits; 3027 | /* We overwrite tree[n].Dad which is no longer needed */ 3028 | 3029 | if (n > max_code) { continue; } /* not a leaf node */ 3030 | 3031 | s.bl_count[bits]++; 3032 | xbits = 0; 3033 | if (n >= base) { 3034 | xbits = extra[n - base]; 3035 | } 3036 | f = tree[n * 2]/*.Freq*/; 3037 | s.opt_len += f * (bits + xbits); 3038 | if (has_stree) { 3039 | s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits); 3040 | } 3041 | } 3042 | if (overflow === 0) { return; } 3043 | 3044 | // Trace((stderr,"\nbit length overflow\n")); 3045 | /* This happens for example on obj2 and pic of the Calgary corpus */ 3046 | 3047 | /* Find the first bit length which could increase: */ 3048 | do { 3049 | bits = max_length - 1; 3050 | while (s.bl_count[bits] === 0) { bits--; } 3051 | s.bl_count[bits]--; /* move one leaf down the tree */ 3052 | s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */ 3053 | s.bl_count[max_length]--; 3054 | /* The brother of the overflow item also moves one step up, 3055 | * but this does not affect bl_count[max_length] 3056 | */ 3057 | overflow -= 2; 3058 | } while (overflow > 0); 3059 | 3060 | /* Now recompute all bit lengths, scanning in increasing frequency. 3061 | * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all 3062 | * lengths instead of fixing only the wrong ones. This idea is taken 3063 | * from 'ar' written by Haruhiko Okumura.) 3064 | */ 3065 | for (bits = max_length; bits !== 0; bits--) { 3066 | n = s.bl_count[bits]; 3067 | while (n !== 0) { 3068 | m = s.heap[--h]; 3069 | if (m > max_code) { continue; } 3070 | if (tree[m * 2 + 1]/*.Len*/ !== bits) { 3071 | // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); 3072 | s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/; 3073 | tree[m * 2 + 1]/*.Len*/ = bits; 3074 | } 3075 | n--; 3076 | } 3077 | } 3078 | } 3079 | 3080 | 3081 | /* =========================================================================== 3082 | * Generate the codes for a given tree and bit counts (which need not be 3083 | * optimal). 3084 | * IN assertion: the array bl_count contains the bit length statistics for 3085 | * the given tree and the field len is set for all tree elements. 3086 | * OUT assertion: the field code is set for all tree elements of non 3087 | * zero code length. 3088 | */ 3089 | function gen_codes(tree, max_code, bl_count) 3090 | // ct_data *tree; /* the tree to decorate */ 3091 | // int max_code; /* largest code with non zero frequency */ 3092 | // ushf *bl_count; /* number of codes at each bit length */ 3093 | { 3094 | var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */ 3095 | var code = 0; /* running code value */ 3096 | var bits; /* bit index */ 3097 | var n; /* code index */ 3098 | 3099 | /* The distribution counts are first used to generate the code values 3100 | * without bit reversal. 3101 | */ 3102 | for (bits = 1; bits <= MAX_BITS; bits++) { 3103 | next_code[bits] = code = (code + bl_count[bits - 1]) << 1; 3104 | } 3105 | /* Check that the bit counts in bl_count are consistent. The last code 3106 | * must be all ones. 3107 | */ 3108 | //Assert (code + bl_count[MAX_BITS]-1 == (1< length code (0..28) */ 3149 | length = 0; 3150 | for (code = 0; code < LENGTH_CODES - 1; code++) { 3151 | base_length[code] = length; 3152 | for (n = 0; n < (1 << extra_lbits[code]); n++) { 3153 | _length_code[length++] = code; 3154 | } 3155 | } 3156 | //Assert (length == 256, "tr_static_init: length != 256"); 3157 | /* Note that the length 255 (match length 258) can be represented 3158 | * in two different ways: code 284 + 5 bits or code 285, so we 3159 | * overwrite length_code[255] to use the best encoding: 3160 | */ 3161 | _length_code[length - 1] = code; 3162 | 3163 | /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ 3164 | dist = 0; 3165 | for (code = 0; code < 16; code++) { 3166 | base_dist[code] = dist; 3167 | for (n = 0; n < (1 << extra_dbits[code]); n++) { 3168 | _dist_code[dist++] = code; 3169 | } 3170 | } 3171 | //Assert (dist == 256, "tr_static_init: dist != 256"); 3172 | dist >>= 7; /* from now on, all distances are divided by 128 */ 3173 | for (; code < D_CODES; code++) { 3174 | base_dist[code] = dist << 7; 3175 | for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) { 3176 | _dist_code[256 + dist++] = code; 3177 | } 3178 | } 3179 | //Assert (dist == 256, "tr_static_init: 256+dist != 512"); 3180 | 3181 | /* Construct the codes of the static literal tree */ 3182 | for (bits = 0; bits <= MAX_BITS; bits++) { 3183 | bl_count[bits] = 0; 3184 | } 3185 | 3186 | n = 0; 3187 | while (n <= 143) { 3188 | static_ltree[n * 2 + 1]/*.Len*/ = 8; 3189 | n++; 3190 | bl_count[8]++; 3191 | } 3192 | while (n <= 255) { 3193 | static_ltree[n * 2 + 1]/*.Len*/ = 9; 3194 | n++; 3195 | bl_count[9]++; 3196 | } 3197 | while (n <= 279) { 3198 | static_ltree[n * 2 + 1]/*.Len*/ = 7; 3199 | n++; 3200 | bl_count[7]++; 3201 | } 3202 | while (n <= 287) { 3203 | static_ltree[n * 2 + 1]/*.Len*/ = 8; 3204 | n++; 3205 | bl_count[8]++; 3206 | } 3207 | /* Codes 286 and 287 do not exist, but we must include them in the 3208 | * tree construction to get a canonical Huffman tree (longest code 3209 | * all ones) 3210 | */ 3211 | gen_codes(static_ltree, L_CODES + 1, bl_count); 3212 | 3213 | /* The static distance tree is trivial: */ 3214 | for (n = 0; n < D_CODES; n++) { 3215 | static_dtree[n * 2 + 1]/*.Len*/ = 5; 3216 | static_dtree[n * 2]/*.Code*/ = bi_reverse(n, 5); 3217 | } 3218 | 3219 | // Now data ready and we can init static trees 3220 | static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS); 3221 | static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS); 3222 | static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS); 3223 | 3224 | //static_init_done = true; 3225 | } 3226 | 3227 | 3228 | /* =========================================================================== 3229 | * Initialize a new block. 3230 | */ 3231 | function init_block(s) { 3232 | var n; /* iterates over tree elements */ 3233 | 3234 | /* Initialize the trees. */ 3235 | for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; } 3236 | for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; } 3237 | for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2]/*.Freq*/ = 0; } 3238 | 3239 | s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1; 3240 | s.opt_len = s.static_len = 0; 3241 | s.last_lit = s.matches = 0; 3242 | } 3243 | 3244 | 3245 | /* =========================================================================== 3246 | * Flush the bit buffer and align the output on a byte boundary 3247 | */ 3248 | function bi_windup(s) 3249 | { 3250 | if (s.bi_valid > 8) { 3251 | put_short(s, s.bi_buf); 3252 | } else if (s.bi_valid > 0) { 3253 | //put_byte(s, (Byte)s->bi_buf); 3254 | s.pending_buf[s.pending++] = s.bi_buf; 3255 | } 3256 | s.bi_buf = 0; 3257 | s.bi_valid = 0; 3258 | } 3259 | 3260 | /* =========================================================================== 3261 | * Copy a stored block, storing first the length and its 3262 | * one's complement if requested. 3263 | */ 3264 | function copy_block(s, buf, len, header) 3265 | //DeflateState *s; 3266 | //charf *buf; /* the input data */ 3267 | //unsigned len; /* its length */ 3268 | //int header; /* true if block header must be written */ 3269 | { 3270 | bi_windup(s); /* align on byte boundary */ 3271 | 3272 | if (header) { 3273 | put_short(s, len); 3274 | put_short(s, ~len); 3275 | } 3276 | // while (len--) { 3277 | // put_byte(s, *buf++); 3278 | // } 3279 | utils.arraySet(s.pending_buf, s.window, buf, len, s.pending); 3280 | s.pending += len; 3281 | } 3282 | 3283 | /* =========================================================================== 3284 | * Compares to subtrees, using the tree depth as tie breaker when 3285 | * the subtrees have equal frequency. This minimizes the worst case length. 3286 | */ 3287 | function smaller(tree, n, m, depth) { 3288 | var _n2 = n * 2; 3289 | var _m2 = m * 2; 3290 | return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ || 3291 | (tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m])); 3292 | } 3293 | 3294 | /* =========================================================================== 3295 | * Restore the heap property by moving down the tree starting at node k, 3296 | * exchanging a node with the smallest of its two sons if necessary, stopping 3297 | * when the heap property is re-established (each father smaller than its 3298 | * two sons). 3299 | */ 3300 | function pqdownheap(s, tree, k) 3301 | // deflate_state *s; 3302 | // ct_data *tree; /* the tree to restore */ 3303 | // int k; /* node to move down */ 3304 | { 3305 | var v = s.heap[k]; 3306 | var j = k << 1; /* left son of k */ 3307 | while (j <= s.heap_len) { 3308 | /* Set j to the smallest of the two sons: */ 3309 | if (j < s.heap_len && 3310 | smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) { 3311 | j++; 3312 | } 3313 | /* Exit if v is smaller than both sons */ 3314 | if (smaller(tree, v, s.heap[j], s.depth)) { break; } 3315 | 3316 | /* Exchange v with the smallest son */ 3317 | s.heap[k] = s.heap[j]; 3318 | k = j; 3319 | 3320 | /* And continue down the tree, setting j to the left son of k */ 3321 | j <<= 1; 3322 | } 3323 | s.heap[k] = v; 3324 | } 3325 | 3326 | 3327 | // inlined manually 3328 | // var SMALLEST = 1; 3329 | 3330 | /* =========================================================================== 3331 | * Send the block data compressed using the given Huffman trees 3332 | */ 3333 | function compress_block(s, ltree, dtree) 3334 | // deflate_state *s; 3335 | // const ct_data *ltree; /* literal tree */ 3336 | // const ct_data *dtree; /* distance tree */ 3337 | { 3338 | var dist; /* distance of matched string */ 3339 | var lc; /* match length or unmatched char (if dist == 0) */ 3340 | var lx = 0; /* running index in l_buf */ 3341 | var code; /* the code to send */ 3342 | var extra; /* number of extra bits to send */ 3343 | 3344 | if (s.last_lit !== 0) { 3345 | do { 3346 | dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]); 3347 | lc = s.pending_buf[s.l_buf + lx]; 3348 | lx++; 3349 | 3350 | if (dist === 0) { 3351 | send_code(s, lc, ltree); /* send a literal byte */ 3352 | //Tracecv(isgraph(lc), (stderr," '%c' ", lc)); 3353 | } else { 3354 | /* Here, lc is the match length - MIN_MATCH */ 3355 | code = _length_code[lc]; 3356 | send_code(s, code + LITERALS + 1, ltree); /* send the length code */ 3357 | extra = extra_lbits[code]; 3358 | if (extra !== 0) { 3359 | lc -= base_length[code]; 3360 | send_bits(s, lc, extra); /* send the extra length bits */ 3361 | } 3362 | dist--; /* dist is now the match distance - 1 */ 3363 | code = d_code(dist); 3364 | //Assert (code < D_CODES, "bad d_code"); 3365 | 3366 | send_code(s, code, dtree); /* send the distance code */ 3367 | extra = extra_dbits[code]; 3368 | if (extra !== 0) { 3369 | dist -= base_dist[code]; 3370 | send_bits(s, dist, extra); /* send the extra distance bits */ 3371 | } 3372 | } /* literal or match pair ? */ 3373 | 3374 | /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ 3375 | //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, 3376 | // "pendingBuf overflow"); 3377 | 3378 | } while (lx < s.last_lit); 3379 | } 3380 | 3381 | send_code(s, END_BLOCK, ltree); 3382 | } 3383 | 3384 | 3385 | /* =========================================================================== 3386 | * Construct one Huffman tree and assigns the code bit strings and lengths. 3387 | * Update the total bit length for the current block. 3388 | * IN assertion: the field freq is set for all tree elements. 3389 | * OUT assertions: the fields len and code are set to the optimal bit length 3390 | * and corresponding code. The length opt_len is updated; static_len is 3391 | * also updated if stree is not null. The field max_code is set. 3392 | */ 3393 | function build_tree(s, desc) 3394 | // deflate_state *s; 3395 | // tree_desc *desc; /* the tree descriptor */ 3396 | { 3397 | var tree = desc.dyn_tree; 3398 | var stree = desc.stat_desc.static_tree; 3399 | var has_stree = desc.stat_desc.has_stree; 3400 | var elems = desc.stat_desc.elems; 3401 | var n, m; /* iterate over heap elements */ 3402 | var max_code = -1; /* largest code with non zero frequency */ 3403 | var node; /* new node being created */ 3404 | 3405 | /* Construct the initial heap, with least frequent element in 3406 | * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. 3407 | * heap[0] is not used. 3408 | */ 3409 | s.heap_len = 0; 3410 | s.heap_max = HEAP_SIZE; 3411 | 3412 | for (n = 0; n < elems; n++) { 3413 | if (tree[n * 2]/*.Freq*/ !== 0) { 3414 | s.heap[++s.heap_len] = max_code = n; 3415 | s.depth[n] = 0; 3416 | 3417 | } else { 3418 | tree[n * 2 + 1]/*.Len*/ = 0; 3419 | } 3420 | } 3421 | 3422 | /* The pkzip format requires that at least one distance code exists, 3423 | * and that at least one bit should be sent even if there is only one 3424 | * possible code. So to avoid special checks later on we force at least 3425 | * two codes of non zero frequency. 3426 | */ 3427 | while (s.heap_len < 2) { 3428 | node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0); 3429 | tree[node * 2]/*.Freq*/ = 1; 3430 | s.depth[node] = 0; 3431 | s.opt_len--; 3432 | 3433 | if (has_stree) { 3434 | s.static_len -= stree[node * 2 + 1]/*.Len*/; 3435 | } 3436 | /* node is 0 or 1 so it does not have extra bits */ 3437 | } 3438 | desc.max_code = max_code; 3439 | 3440 | /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, 3441 | * establish sub-heaps of increasing lengths: 3442 | */ 3443 | for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); } 3444 | 3445 | /* Construct the Huffman tree by repeatedly combining the least two 3446 | * frequent nodes. 3447 | */ 3448 | node = elems; /* next internal node of the tree */ 3449 | do { 3450 | //pqremove(s, tree, n); /* n = node of least frequency */ 3451 | /*** pqremove ***/ 3452 | n = s.heap[1/*SMALLEST*/]; 3453 | s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--]; 3454 | pqdownheap(s, tree, 1/*SMALLEST*/); 3455 | /***/ 3456 | 3457 | m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */ 3458 | 3459 | s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */ 3460 | s.heap[--s.heap_max] = m; 3461 | 3462 | /* Create a new node father of n and m */ 3463 | tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/; 3464 | s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1; 3465 | tree[n * 2 + 1]/*.Dad*/ = tree[m * 2 + 1]/*.Dad*/ = node; 3466 | 3467 | /* and insert the new node in the heap */ 3468 | s.heap[1/*SMALLEST*/] = node++; 3469 | pqdownheap(s, tree, 1/*SMALLEST*/); 3470 | 3471 | } while (s.heap_len >= 2); 3472 | 3473 | s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/]; 3474 | 3475 | /* At this point, the fields freq and dad are set. We can now 3476 | * generate the bit lengths. 3477 | */ 3478 | gen_bitlen(s, desc); 3479 | 3480 | /* The field len is now set, we can generate the bit codes */ 3481 | gen_codes(tree, max_code, s.bl_count); 3482 | } 3483 | 3484 | 3485 | /* =========================================================================== 3486 | * Scan a literal or distance tree to determine the frequencies of the codes 3487 | * in the bit length tree. 3488 | */ 3489 | function scan_tree(s, tree, max_code) 3490 | // deflate_state *s; 3491 | // ct_data *tree; /* the tree to be scanned */ 3492 | // int max_code; /* and its largest code of non zero frequency */ 3493 | { 3494 | var n; /* iterates over all tree elements */ 3495 | var prevlen = -1; /* last emitted length */ 3496 | var curlen; /* length of current code */ 3497 | 3498 | var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */ 3499 | 3500 | var count = 0; /* repeat count of the current code */ 3501 | var max_count = 7; /* max repeat count */ 3502 | var min_count = 4; /* min repeat count */ 3503 | 3504 | if (nextlen === 0) { 3505 | max_count = 138; 3506 | min_count = 3; 3507 | } 3508 | tree[(max_code + 1) * 2 + 1]/*.Len*/ = 0xffff; /* guard */ 3509 | 3510 | for (n = 0; n <= max_code; n++) { 3511 | curlen = nextlen; 3512 | nextlen = tree[(n + 1) * 2 + 1]/*.Len*/; 3513 | 3514 | if (++count < max_count && curlen === nextlen) { 3515 | continue; 3516 | 3517 | } else if (count < min_count) { 3518 | s.bl_tree[curlen * 2]/*.Freq*/ += count; 3519 | 3520 | } else if (curlen !== 0) { 3521 | 3522 | if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; } 3523 | s.bl_tree[REP_3_6 * 2]/*.Freq*/++; 3524 | 3525 | } else if (count <= 10) { 3526 | s.bl_tree[REPZ_3_10 * 2]/*.Freq*/++; 3527 | 3528 | } else { 3529 | s.bl_tree[REPZ_11_138 * 2]/*.Freq*/++; 3530 | } 3531 | 3532 | count = 0; 3533 | prevlen = curlen; 3534 | 3535 | if (nextlen === 0) { 3536 | max_count = 138; 3537 | min_count = 3; 3538 | 3539 | } else if (curlen === nextlen) { 3540 | max_count = 6; 3541 | min_count = 3; 3542 | 3543 | } else { 3544 | max_count = 7; 3545 | min_count = 4; 3546 | } 3547 | } 3548 | } 3549 | 3550 | 3551 | /* =========================================================================== 3552 | * Send a literal or distance tree in compressed form, using the codes in 3553 | * bl_tree. 3554 | */ 3555 | function send_tree(s, tree, max_code) 3556 | // deflate_state *s; 3557 | // ct_data *tree; /* the tree to be scanned */ 3558 | // int max_code; /* and its largest code of non zero frequency */ 3559 | { 3560 | var n; /* iterates over all tree elements */ 3561 | var prevlen = -1; /* last emitted length */ 3562 | var curlen; /* length of current code */ 3563 | 3564 | var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */ 3565 | 3566 | var count = 0; /* repeat count of the current code */ 3567 | var max_count = 7; /* max repeat count */ 3568 | var min_count = 4; /* min repeat count */ 3569 | 3570 | /* tree[max_code+1].Len = -1; */ /* guard already set */ 3571 | if (nextlen === 0) { 3572 | max_count = 138; 3573 | min_count = 3; 3574 | } 3575 | 3576 | for (n = 0; n <= max_code; n++) { 3577 | curlen = nextlen; 3578 | nextlen = tree[(n + 1) * 2 + 1]/*.Len*/; 3579 | 3580 | if (++count < max_count && curlen === nextlen) { 3581 | continue; 3582 | 3583 | } else if (count < min_count) { 3584 | do { send_code(s, curlen, s.bl_tree); } while (--count !== 0); 3585 | 3586 | } else if (curlen !== 0) { 3587 | if (curlen !== prevlen) { 3588 | send_code(s, curlen, s.bl_tree); 3589 | count--; 3590 | } 3591 | //Assert(count >= 3 && count <= 6, " 3_6?"); 3592 | send_code(s, REP_3_6, s.bl_tree); 3593 | send_bits(s, count - 3, 2); 3594 | 3595 | } else if (count <= 10) { 3596 | send_code(s, REPZ_3_10, s.bl_tree); 3597 | send_bits(s, count - 3, 3); 3598 | 3599 | } else { 3600 | send_code(s, REPZ_11_138, s.bl_tree); 3601 | send_bits(s, count - 11, 7); 3602 | } 3603 | 3604 | count = 0; 3605 | prevlen = curlen; 3606 | if (nextlen === 0) { 3607 | max_count = 138; 3608 | min_count = 3; 3609 | 3610 | } else if (curlen === nextlen) { 3611 | max_count = 6; 3612 | min_count = 3; 3613 | 3614 | } else { 3615 | max_count = 7; 3616 | min_count = 4; 3617 | } 3618 | } 3619 | } 3620 | 3621 | 3622 | /* =========================================================================== 3623 | * Construct the Huffman tree for the bit lengths and return the index in 3624 | * bl_order of the last bit length code to send. 3625 | */ 3626 | function build_bl_tree(s) { 3627 | var max_blindex; /* index of last bit length code of non zero freq */ 3628 | 3629 | /* Determine the bit length frequencies for literal and distance trees */ 3630 | scan_tree(s, s.dyn_ltree, s.l_desc.max_code); 3631 | scan_tree(s, s.dyn_dtree, s.d_desc.max_code); 3632 | 3633 | /* Build the bit length tree: */ 3634 | build_tree(s, s.bl_desc); 3635 | /* opt_len now includes the length of the tree representations, except 3636 | * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. 3637 | */ 3638 | 3639 | /* Determine the number of bit length codes to send. The pkzip format 3640 | * requires that at least 4 bit length codes be sent. (appnote.txt says 3641 | * 3 but the actual value used is 4.) 3642 | */ 3643 | for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) { 3644 | if (s.bl_tree[bl_order[max_blindex] * 2 + 1]/*.Len*/ !== 0) { 3645 | break; 3646 | } 3647 | } 3648 | /* Update opt_len to include the bit length tree and counts */ 3649 | s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; 3650 | //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", 3651 | // s->opt_len, s->static_len)); 3652 | 3653 | return max_blindex; 3654 | } 3655 | 3656 | 3657 | /* =========================================================================== 3658 | * Send the header for a block using dynamic Huffman trees: the counts, the 3659 | * lengths of the bit length codes, the literal tree and the distance tree. 3660 | * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. 3661 | */ 3662 | function send_all_trees(s, lcodes, dcodes, blcodes) 3663 | // deflate_state *s; 3664 | // int lcodes, dcodes, blcodes; /* number of codes for each tree */ 3665 | { 3666 | var rank; /* index in bl_order */ 3667 | 3668 | //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); 3669 | //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, 3670 | // "too many codes"); 3671 | //Tracev((stderr, "\nbl counts: ")); 3672 | send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */ 3673 | send_bits(s, dcodes - 1, 5); 3674 | send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */ 3675 | for (rank = 0; rank < blcodes; rank++) { 3676 | //Tracev((stderr, "\nbl code %2d ", bl_order[rank])); 3677 | send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]/*.Len*/, 3); 3678 | } 3679 | //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); 3680 | 3681 | send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */ 3682 | //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); 3683 | 3684 | send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */ 3685 | //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); 3686 | } 3687 | 3688 | 3689 | /* =========================================================================== 3690 | * Check if the data type is TEXT or BINARY, using the following algorithm: 3691 | * - TEXT if the two conditions below are satisfied: 3692 | * a) There are no non-portable control characters belonging to the 3693 | * "black list" (0..6, 14..25, 28..31). 3694 | * b) There is at least one printable character belonging to the 3695 | * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). 3696 | * - BINARY otherwise. 3697 | * - The following partially-portable control characters form a 3698 | * "gray list" that is ignored in this detection algorithm: 3699 | * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). 3700 | * IN assertion: the fields Freq of dyn_ltree are set. 3701 | */ 3702 | function detect_data_type(s) { 3703 | /* black_mask is the bit mask of black-listed bytes 3704 | * set bits 0..6, 14..25, and 28..31 3705 | * 0xf3ffc07f = binary 11110011111111111100000001111111 3706 | */ 3707 | var black_mask = 0xf3ffc07f; 3708 | var n; 3709 | 3710 | /* Check for non-textual ("black-listed") bytes. */ 3711 | for (n = 0; n <= 31; n++, black_mask >>>= 1) { 3712 | if ((black_mask & 1) && (s.dyn_ltree[n * 2]/*.Freq*/ !== 0)) { 3713 | return Z_BINARY; 3714 | } 3715 | } 3716 | 3717 | /* Check for textual ("white-listed") bytes. */ 3718 | if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 || 3719 | s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) { 3720 | return Z_TEXT; 3721 | } 3722 | for (n = 32; n < LITERALS; n++) { 3723 | if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) { 3724 | return Z_TEXT; 3725 | } 3726 | } 3727 | 3728 | /* There are no "black-listed" or "white-listed" bytes: 3729 | * this stream either is empty or has tolerated ("gray-listed") bytes only. 3730 | */ 3731 | return Z_BINARY; 3732 | } 3733 | 3734 | 3735 | var static_init_done = false; 3736 | 3737 | /* =========================================================================== 3738 | * Initialize the tree data structures for a new zlib stream. 3739 | */ 3740 | function _tr_init(s) 3741 | { 3742 | 3743 | if (!static_init_done) { 3744 | tr_static_init(); 3745 | static_init_done = true; 3746 | } 3747 | 3748 | s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc); 3749 | s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc); 3750 | s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc); 3751 | 3752 | s.bi_buf = 0; 3753 | s.bi_valid = 0; 3754 | 3755 | /* Initialize the first block of the first file: */ 3756 | init_block(s); 3757 | } 3758 | 3759 | 3760 | /* =========================================================================== 3761 | * Send a stored block 3762 | */ 3763 | function _tr_stored_block(s, buf, stored_len, last) 3764 | //DeflateState *s; 3765 | //charf *buf; /* input block */ 3766 | //ulg stored_len; /* length of input block */ 3767 | //int last; /* one if this is the last block for a file */ 3768 | { 3769 | send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */ 3770 | copy_block(s, buf, stored_len, true); /* with header */ 3771 | } 3772 | 3773 | 3774 | /* =========================================================================== 3775 | * Send one empty static block to give enough lookahead for inflate. 3776 | * This takes 10 bits, of which 7 may remain in the bit buffer. 3777 | */ 3778 | function _tr_align(s) { 3779 | send_bits(s, STATIC_TREES << 1, 3); 3780 | send_code(s, END_BLOCK, static_ltree); 3781 | bi_flush(s); 3782 | } 3783 | 3784 | 3785 | /* =========================================================================== 3786 | * Determine the best encoding for the current block: dynamic trees, static 3787 | * trees or store, and output the encoded block to the zip file. 3788 | */ 3789 | function _tr_flush_block(s, buf, stored_len, last) 3790 | //DeflateState *s; 3791 | //charf *buf; /* input block, or NULL if too old */ 3792 | //ulg stored_len; /* length of input block */ 3793 | //int last; /* one if this is the last block for a file */ 3794 | { 3795 | var opt_lenb, static_lenb; /* opt_len and static_len in bytes */ 3796 | var max_blindex = 0; /* index of last bit length code of non zero freq */ 3797 | 3798 | /* Build the Huffman trees unless a stored block is forced */ 3799 | if (s.level > 0) { 3800 | 3801 | /* Check if the file is binary or text */ 3802 | if (s.strm.data_type === Z_UNKNOWN) { 3803 | s.strm.data_type = detect_data_type(s); 3804 | } 3805 | 3806 | /* Construct the literal and distance trees */ 3807 | build_tree(s, s.l_desc); 3808 | // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, 3809 | // s->static_len)); 3810 | 3811 | build_tree(s, s.d_desc); 3812 | // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, 3813 | // s->static_len)); 3814 | /* At this point, opt_len and static_len are the total bit lengths of 3815 | * the compressed block data, excluding the tree representations. 3816 | */ 3817 | 3818 | /* Build the bit length tree for the above two trees, and get the index 3819 | * in bl_order of the last bit length code to send. 3820 | */ 3821 | max_blindex = build_bl_tree(s); 3822 | 3823 | /* Determine the best encoding. Compute the block lengths in bytes. */ 3824 | opt_lenb = (s.opt_len + 3 + 7) >>> 3; 3825 | static_lenb = (s.static_len + 3 + 7) >>> 3; 3826 | 3827 | // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", 3828 | // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, 3829 | // s->last_lit)); 3830 | 3831 | if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; } 3832 | 3833 | } else { 3834 | // Assert(buf != (char*)0, "lost buf"); 3835 | opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ 3836 | } 3837 | 3838 | if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) { 3839 | /* 4: two words for the lengths */ 3840 | 3841 | /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. 3842 | * Otherwise we can't have processed more than WSIZE input bytes since 3843 | * the last block flush, because compression would have been 3844 | * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to 3845 | * transform a block into a stored block. 3846 | */ 3847 | _tr_stored_block(s, buf, stored_len, last); 3848 | 3849 | } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) { 3850 | 3851 | send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3); 3852 | compress_block(s, static_ltree, static_dtree); 3853 | 3854 | } else { 3855 | send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3); 3856 | send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1); 3857 | compress_block(s, s.dyn_ltree, s.dyn_dtree); 3858 | } 3859 | // Assert (s->compressed_len == s->bits_sent, "bad compressed size"); 3860 | /* The above check is made mod 2^32, for files larger than 512 MB 3861 | * and uLong implemented on 32 bits. 3862 | */ 3863 | init_block(s); 3864 | 3865 | if (last) { 3866 | bi_windup(s); 3867 | } 3868 | // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, 3869 | // s->compressed_len-7*last)); 3870 | } 3871 | 3872 | /* =========================================================================== 3873 | * Save the match info and tally the frequency counts. Return true if 3874 | * the current block must be flushed. 3875 | */ 3876 | function _tr_tally(s, dist, lc) 3877 | // deflate_state *s; 3878 | // unsigned dist; /* distance of matched string */ 3879 | // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ 3880 | { 3881 | //var out_length, in_length, dcode; 3882 | 3883 | s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff; 3884 | s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff; 3885 | 3886 | s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff; 3887 | s.last_lit++; 3888 | 3889 | if (dist === 0) { 3890 | /* lc is the unmatched char */ 3891 | s.dyn_ltree[lc * 2]/*.Freq*/++; 3892 | } else { 3893 | s.matches++; 3894 | /* Here, lc is the match length - MIN_MATCH */ 3895 | dist--; /* dist = match distance - 1 */ 3896 | //Assert((ush)dist < (ush)MAX_DIST(s) && 3897 | // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && 3898 | // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); 3899 | 3900 | s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++; 3901 | s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++; 3902 | } 3903 | 3904 | // (!) This block is disabled in zlib defailts, 3905 | // don't enable it for binary compatibility 3906 | 3907 | //#ifdef TRUNCATE_BLOCK 3908 | // /* Try to guess if it is profitable to stop the current block here */ 3909 | // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) { 3910 | // /* Compute an upper bound for the compressed length */ 3911 | // out_length = s.last_lit*8; 3912 | // in_length = s.strstart - s.block_start; 3913 | // 3914 | // for (dcode = 0; dcode < D_CODES; dcode++) { 3915 | // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]); 3916 | // } 3917 | // out_length >>>= 3; 3918 | // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", 3919 | // // s->last_lit, in_length, out_length, 3920 | // // 100L - out_length*100L/in_length)); 3921 | // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) { 3922 | // return true; 3923 | // } 3924 | // } 3925 | //#endif 3926 | 3927 | return (s.last_lit === s.lit_bufsize - 1); 3928 | /* We avoid equality with lit_bufsize because of wraparound at 64K 3929 | * on 16 bit machines and because stored blocks are restricted to 3930 | * 64K-1 bytes. 3931 | */ 3932 | } 3933 | 3934 | exports._tr_init = _tr_init; 3935 | exports._tr_stored_block = _tr_stored_block; 3936 | exports._tr_flush_block = _tr_flush_block; 3937 | exports._tr_tally = _tr_tally; 3938 | exports._tr_align = _tr_align; 3939 | 3940 | },{"../utils/common":2}],9:[function(require,module,exports){ 3941 | 'use strict'; 3942 | 3943 | // (C) 1995-2013 Jean-loup Gailly and Mark Adler 3944 | // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin 3945 | // 3946 | // This software is provided 'as-is', without any express or implied 3947 | // warranty. In no event will the authors be held liable for any damages 3948 | // arising from the use of this software. 3949 | // 3950 | // Permission is granted to anyone to use this software for any purpose, 3951 | // including commercial applications, and to alter it and redistribute it 3952 | // freely, subject to the following restrictions: 3953 | // 3954 | // 1. The origin of this software must not be misrepresented; you must not 3955 | // claim that you wrote the original software. If you use this software 3956 | // in a product, an acknowledgment in the product documentation would be 3957 | // appreciated but is not required. 3958 | // 2. Altered source versions must be plainly marked as such, and must not be 3959 | // misrepresented as being the original software. 3960 | // 3. This notice may not be removed or altered from any source distribution. 3961 | 3962 | function ZStream() { 3963 | /* next input byte */ 3964 | this.input = null; // JS specific, because we have no pointers 3965 | this.next_in = 0; 3966 | /* number of bytes available at input */ 3967 | this.avail_in = 0; 3968 | /* total number of input bytes read so far */ 3969 | this.total_in = 0; 3970 | /* next output byte should be put there */ 3971 | this.output = null; // JS specific, because we have no pointers 3972 | this.next_out = 0; 3973 | /* remaining free space at output */ 3974 | this.avail_out = 0; 3975 | /* total number of bytes output so far */ 3976 | this.total_out = 0; 3977 | /* last error message, NULL if no error */ 3978 | this.msg = ''/*Z_NULL*/; 3979 | /* not visible by applications */ 3980 | this.state = null; 3981 | /* best guess about the data type: binary or text */ 3982 | this.data_type = 2/*Z_UNKNOWN*/; 3983 | /* adler32 value of the uncompressed data */ 3984 | this.adler = 0; 3985 | } 3986 | 3987 | module.exports = ZStream; 3988 | 3989 | },{}],10:[function(require,module,exports){ 3990 | var compressGzip = require('pako/lib/deflate').gzip; 3991 | 3992 | function highlighter(document, options) { 3993 | function sendSnippet(snippet) { 3994 | function executor(resolve, reject) { 3995 | var xhr = new XMLHttpRequest(); 3996 | xhr.open('POST', encodeURI('https://api.photon.sh/snippets')); 3997 | xhr.setRequestHeader('Authorization', 'Token ' + options.apiKey); 3998 | xhr.setRequestHeader('Content-Type', 'text/html'); 3999 | xhr.setRequestHeader('Content-Encoding', 'gzip'); 4000 | xhr.setRequestHeader('Library', 'javascript'); 4001 | 4002 | xhr.onload = function () { 4003 | if (xhr.status === 200 && xhr.responseText) { 4004 | var div = document.createElement('div'); 4005 | div.innerHTML = xhr.responseText; 4006 | snippet.parentNode.parentNode.replaceChild(div.firstChild, snippet.parentNode); 4007 | resolve(); 4008 | } else if (xhr.status >= 400) { 4009 | var error; 4010 | try { 4011 | error = xhr.responseText; 4012 | } catch (err) { 4013 | error = JSON.stringify({ error: { type: 'unknown_error', message: 'Unknown error.' } }); 4014 | } 4015 | 4016 | reject(new Error(error)); 4017 | } 4018 | } 4019 | 4020 | xhr.onerror = function () { 4021 | reject(new Error(JSON.stringify({ error: { type: 'unknown_error', message: 'Unknown error.' } }))); 4022 | } 4023 | 4024 | xhr.send(compressGzip(snippet.outerHTML)); 4025 | } 4026 | 4027 | return (typeof Promise === 'function') ? new Promise(executor) : executor(function () {}, function (err) { throw(err); }); 4028 | } 4029 | 4030 | var snippets = document.querySelectorAll('pre code[class*=language-], pre code[class*=lang-], pre samp[class*=language-], pre samp[class*=lang-]'); 4031 | 4032 | return Array.prototype.slice.call(snippets) 4033 | .filter(function(snippet) { return (snippet.textContent !== '') }) 4034 | .map(sendSnippet) 4035 | } 4036 | 4037 | module.exports = highlighter 4038 | 4039 | },{"pako/lib/deflate":1}],11:[function(require,module,exports){ 4040 | var highlighter = require('./highlighter'); 4041 | 4042 | function photon() { 4043 | var apiKey = ''; 4044 | 4045 | return { 4046 | setup: function setup(options) { 4047 | if (options === undefined) { 4048 | options = {}; 4049 | } 4050 | 4051 | if (typeof options !== 'object' || options === null) { 4052 | throw new Error('Setup\'s first argument (options) must be an object.'); 4053 | } 4054 | 4055 | if (options.apiKey) { 4056 | apiKey = options.apiKey; 4057 | } 4058 | }, 4059 | highlight: function highlight(options) { 4060 | if (options === undefined) { 4061 | options = {}; 4062 | } 4063 | 4064 | if (typeof options !== 'object' || options === null) { 4065 | throw new Error('Highlight\'s second argument (options) must be an object.'); 4066 | } 4067 | 4068 | if (apiKey === '' && options.apiKey === undefined) { 4069 | throw new Error('Missing API key.'); 4070 | } 4071 | 4072 | return highlighter(document, { apiKey: options.apiKey || apiKey }); 4073 | } 4074 | } 4075 | } 4076 | 4077 | module.exports = photon() 4078 | 4079 | },{"./highlighter":10}]},{},[11])(11) 4080 | }); -------------------------------------------------------------------------------- /dist/photon.min.js: -------------------------------------------------------------------------------- 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.photon=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o0){opt.windowBits=-opt.windowBits}else if(opt.gzip&&opt.windowBits>0&&opt.windowBits<16){opt.windowBits+=16}this.err=0;this.msg="";this.ended=false;this.chunks=[];this.strm=new ZStream;this.strm.avail_out=0;var status=zlib_deflate.deflateInit2(this.strm,opt.level,opt.method,opt.windowBits,opt.memLevel,opt.strategy);if(status!==Z_OK){throw new Error(msg[status])}if(opt.header){zlib_deflate.deflateSetHeader(this.strm,opt.header)}if(opt.dictionary){var dict;if(typeof opt.dictionary==="string"){dict=strings.string2buf(opt.dictionary)}else if(toString.call(opt.dictionary)==="[object ArrayBuffer]"){dict=new Uint8Array(opt.dictionary)}else{dict=opt.dictionary}status=zlib_deflate.deflateSetDictionary(this.strm,dict);if(status!==Z_OK){throw new Error(msg[status])}this._dict_set=true}}Deflate.prototype.push=function(data,mode){var strm=this.strm;var chunkSize=this.options.chunkSize;var status,_mode;if(this.ended){return false}_mode=mode===~~mode?mode:mode===true?Z_FINISH:Z_NO_FLUSH;if(typeof data==="string"){strm.input=strings.string2buf(data)}else if(toString.call(data)==="[object ArrayBuffer]"){strm.input=new Uint8Array(data)}else{strm.input=data}strm.next_in=0;strm.avail_in=strm.input.length;do{if(strm.avail_out===0){strm.output=new utils.Buf8(chunkSize);strm.next_out=0;strm.avail_out=chunkSize}status=zlib_deflate.deflate(strm,_mode);if(status!==Z_STREAM_END&&status!==Z_OK){this.onEnd(status);this.ended=true;return false}if(strm.avail_out===0||strm.avail_in===0&&(_mode===Z_FINISH||_mode===Z_SYNC_FLUSH)){if(this.options.to==="string"){this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output,strm.next_out)))}else{this.onData(utils.shrinkBuf(strm.output,strm.next_out))}}}while((strm.avail_in>0||strm.avail_out===0)&&status!==Z_STREAM_END);if(_mode===Z_FINISH){status=zlib_deflate.deflateEnd(this.strm);this.onEnd(status);this.ended=true;return status===Z_OK}if(_mode===Z_SYNC_FLUSH){this.onEnd(Z_OK);strm.avail_out=0;return true}return true};Deflate.prototype.onData=function(chunk){this.chunks.push(chunk)};Deflate.prototype.onEnd=function(status){if(status===Z_OK){if(this.options.to==="string"){this.result=this.chunks.join("")}else{this.result=utils.flattenChunks(this.chunks)}}this.chunks=[];this.err=status;this.msg=this.strm.msg};function deflate(input,options){var deflator=new Deflate(options);deflator.push(input,true);if(deflator.err){throw deflator.msg||msg[deflator.err]}return deflator.result}function deflateRaw(input,options){options=options||{};options.raw=true;return deflate(input,options)}function gzip(input,options){options=options||{};options.gzip=true;return deflate(input,options)}exports.Deflate=Deflate;exports.deflate=deflate;exports.deflateRaw=deflateRaw;exports.gzip=gzip},{"./utils/common":2,"./utils/strings":3,"./zlib/deflate":6,"./zlib/messages":7,"./zlib/zstream":9}],2:[function(require,module,exports){"use strict";var TYPED_OK=typeof Uint8Array!=="undefined"&&typeof Uint16Array!=="undefined"&&typeof Int32Array!=="undefined";exports.assign=function(obj){var sources=Array.prototype.slice.call(arguments,1);while(sources.length){var source=sources.shift();if(!source){continue}if(typeof source!=="object"){throw new TypeError(source+"must be non-object")}for(var p in source){if(source.hasOwnProperty(p)){obj[p]=source[p]}}}return obj};exports.shrinkBuf=function(buf,size){if(buf.length===size){return buf}if(buf.subarray){return buf.subarray(0,size)}buf.length=size;return buf};var fnTyped={arraySet:function(dest,src,src_offs,len,dest_offs){if(src.subarray&&dest.subarray){dest.set(src.subarray(src_offs,src_offs+len),dest_offs);return}for(var i=0;i=252?6:q>=248?5:q>=240?4:q>=224?3:q>=192?2:1}_utf8len[254]=_utf8len[254]=1;exports.string2buf=function(str){var buf,c,c2,m_pos,i,str_len=str.length,buf_len=0;for(m_pos=0;m_pos>>6;buf[i++]=128|c&63}else if(c<65536){buf[i++]=224|c>>>12;buf[i++]=128|c>>>6&63;buf[i++]=128|c&63}else{buf[i++]=240|c>>>18;buf[i++]=128|c>>>12&63;buf[i++]=128|c>>>6&63;buf[i++]=128|c&63}}return buf};function buf2binstring(buf,len){if(len<65537){if(buf.subarray&&STR_APPLY_UIA_OK||!buf.subarray&&STR_APPLY_OK){return String.fromCharCode.apply(null,utils.shrinkBuf(buf,len))}}var result="";for(var i=0;i4){utf16buf[out++]=65533;i+=c_len-1;continue}c&=c_len===2?31:c_len===3?15:7;while(c_len>1&&i1){utf16buf[out++]=65533;continue}if(c<65536){utf16buf[out++]=c}else{c-=65536;utf16buf[out++]=55296|c>>10&1023;utf16buf[out++]=56320|c&1023}}return buf2binstring(utf16buf,out)};exports.utf8border=function(buf,max){var pos;max=max||buf.length;if(max>buf.length){max=buf.length}pos=max-1;while(pos>=0&&(buf[pos]&192)===128){pos--}if(pos<0){return max}if(pos===0){return max}return pos+_utf8len[buf[pos]]>max?pos:max}},{"./common":2}],4:[function(require,module,exports){"use strict";function adler32(adler,buf,len,pos){var s1=adler&65535|0,s2=adler>>>16&65535|0,n=0;while(len!==0){n=len>2e3?2e3:len;len-=n;do{s1=s1+buf[pos++]|0;s2=s2+s1|0}while(--n);s1%=65521;s2%=65521}return s1|s2<<16|0}module.exports=adler32},{}],5:[function(require,module,exports){"use strict";function makeTable(){var c,table=[];for(var n=0;n<256;n++){c=n;for(var k=0;k<8;k++){c=c&1?3988292384^c>>>1:c>>>1}table[n]=c}return table}var crcTable=makeTable();function crc32(crc,buf,len,pos){var t=crcTable,end=pos+len;crc^=-1;for(var i=pos;i>>8^t[(crc^buf[i])&255]}return crc^-1}module.exports=crc32},{}],6:[function(require,module,exports){"use strict";var utils=require("../utils/common");var trees=require("./trees");var adler32=require("./adler32");var crc32=require("./crc32");var msg=require("./messages");var Z_NO_FLUSH=0;var Z_PARTIAL_FLUSH=1;var Z_FULL_FLUSH=3;var Z_FINISH=4;var Z_BLOCK=5;var Z_OK=0;var Z_STREAM_END=1;var Z_STREAM_ERROR=-2;var Z_DATA_ERROR=-3;var Z_BUF_ERROR=-5;var Z_DEFAULT_COMPRESSION=-1;var Z_FILTERED=1;var Z_HUFFMAN_ONLY=2;var Z_RLE=3;var Z_FIXED=4;var Z_DEFAULT_STRATEGY=0;var Z_UNKNOWN=2;var Z_DEFLATED=8;var MAX_MEM_LEVEL=9;var MAX_WBITS=15;var DEF_MEM_LEVEL=8;var LENGTH_CODES=29;var LITERALS=256;var L_CODES=LITERALS+1+LENGTH_CODES;var D_CODES=30;var BL_CODES=19;var HEAP_SIZE=2*L_CODES+1;var MAX_BITS=15;var MIN_MATCH=3;var MAX_MATCH=258;var MIN_LOOKAHEAD=MAX_MATCH+MIN_MATCH+1;var PRESET_DICT=32;var INIT_STATE=42;var EXTRA_STATE=69;var NAME_STATE=73;var COMMENT_STATE=91;var HCRC_STATE=103;var BUSY_STATE=113;var FINISH_STATE=666;var BS_NEED_MORE=1;var BS_BLOCK_DONE=2;var BS_FINISH_STARTED=3;var BS_FINISH_DONE=4;var OS_CODE=3;function err(strm,errorCode){strm.msg=msg[errorCode];return errorCode}function rank(f){return(f<<1)-(f>4?9:0)}function zero(buf){var len=buf.length;while(--len>=0){buf[len]=0}}function flush_pending(strm){var s=strm.state;var len=s.pending;if(len>strm.avail_out){len=strm.avail_out}if(len===0){return}utils.arraySet(strm.output,s.pending_buf,s.pending_out,len,strm.next_out);strm.next_out+=len;s.pending_out+=len;strm.total_out+=len;strm.avail_out-=len;s.pending-=len;if(s.pending===0){s.pending_out=0}}function flush_block_only(s,last){trees._tr_flush_block(s,s.block_start>=0?s.block_start:-1,s.strstart-s.block_start,last);s.block_start=s.strstart;flush_pending(s.strm)}function put_byte(s,b){s.pending_buf[s.pending++]=b}function putShortMSB(s,b){s.pending_buf[s.pending++]=b>>>8&255;s.pending_buf[s.pending++]=b&255}function read_buf(strm,buf,start,size){var len=strm.avail_in;if(len>size){len=size}if(len===0){return 0}strm.avail_in-=len;utils.arraySet(buf,strm.input,strm.next_in,len,start);if(strm.state.wrap===1){strm.adler=adler32(strm.adler,buf,len,start)}else if(strm.state.wrap===2){strm.adler=crc32(strm.adler,buf,len,start)}strm.next_in+=len;strm.total_in+=len;return len}function longest_match(s,cur_match){var chain_length=s.max_chain_length;var scan=s.strstart;var match;var len;var best_len=s.prev_length;var nice_match=s.nice_match;var limit=s.strstart>s.w_size-MIN_LOOKAHEAD?s.strstart-(s.w_size-MIN_LOOKAHEAD):0;var _win=s.window;var wmask=s.w_mask;var prev=s.prev;var strend=s.strstart+MAX_MATCH;var scan_end1=_win[scan+best_len-1];var scan_end=_win[scan+best_len];if(s.prev_length>=s.good_match){chain_length>>=2}if(nice_match>s.lookahead){nice_match=s.lookahead}do{match=cur_match;if(_win[match+best_len]!==scan_end||_win[match+best_len-1]!==scan_end1||_win[match]!==_win[scan]||_win[++match]!==_win[scan+1]){continue}scan+=2;match++;do{}while(_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&_win[++scan]===_win[++match]&&scanbest_len){s.match_start=cur_match;best_len=len;if(len>=nice_match){break}scan_end1=_win[scan+best_len-1];scan_end=_win[scan+best_len]}}while((cur_match=prev[cur_match&wmask])>limit&&--chain_length!==0);if(best_len<=s.lookahead){return best_len}return s.lookahead}function fill_window(s){var _w_size=s.w_size;var p,n,m,more,str;do{more=s.window_size-s.lookahead-s.strstart;if(s.strstart>=_w_size+(_w_size-MIN_LOOKAHEAD)){utils.arraySet(s.window,s.window,_w_size,_w_size,0);s.match_start-=_w_size;s.strstart-=_w_size;s.block_start-=_w_size;n=s.hash_size;p=n;do{m=s.head[--p];s.head[p]=m>=_w_size?m-_w_size:0}while(--n);n=_w_size;p=n;do{m=s.prev[--p];s.prev[p]=m>=_w_size?m-_w_size:0}while(--n);more+=_w_size}if(s.strm.avail_in===0){break}n=read_buf(s.strm,s.window,s.strstart+s.lookahead,more);s.lookahead+=n;if(s.lookahead+s.insert>=MIN_MATCH){str=s.strstart-s.insert;s.ins_h=s.window[str];s.ins_h=(s.ins_h<s.pending_buf_size-5){max_block_size=s.pending_buf_size-5}for(;;){if(s.lookahead<=1){fill_window(s);if(s.lookahead===0&&flush===Z_NO_FLUSH){return BS_NEED_MORE}if(s.lookahead===0){break}}s.strstart+=s.lookahead;s.lookahead=0;var max_start=s.block_start+max_block_size;if(s.strstart===0||s.strstart>=max_start){s.lookahead=s.strstart-max_start;s.strstart=max_start;flush_block_only(s,false);if(s.strm.avail_out===0){return BS_NEED_MORE}}if(s.strstart-s.block_start>=s.w_size-MIN_LOOKAHEAD){flush_block_only(s,false);if(s.strm.avail_out===0){return BS_NEED_MORE}}}s.insert=0;if(flush===Z_FINISH){flush_block_only(s,true);if(s.strm.avail_out===0){return BS_FINISH_STARTED}return BS_FINISH_DONE}if(s.strstart>s.block_start){flush_block_only(s,false);if(s.strm.avail_out===0){return BS_NEED_MORE}}return BS_NEED_MORE}function deflate_fast(s,flush){var hash_head;var bflush;for(;;){if(s.lookahead=MIN_MATCH){s.ins_h=(s.ins_h<=MIN_MATCH){bflush=trees._tr_tally(s,s.strstart-s.match_start,s.match_length-MIN_MATCH);s.lookahead-=s.match_length;if(s.match_length<=s.max_lazy_match&&s.lookahead>=MIN_MATCH){s.match_length--;do{s.strstart++;s.ins_h=(s.ins_h<=MIN_MATCH){s.ins_h=(s.ins_h<4096)){s.match_length=MIN_MATCH-1}}if(s.prev_length>=MIN_MATCH&&s.match_length<=s.prev_length){max_insert=s.strstart+s.lookahead-MIN_MATCH;bflush=trees._tr_tally(s,s.strstart-1-s.prev_match,s.prev_length-MIN_MATCH);s.lookahead-=s.prev_length-1;s.prev_length-=2;do{if(++s.strstart<=max_insert){s.ins_h=(s.ins_h<=MIN_MATCH&&s.strstart>0){scan=s.strstart-1;prev=_win[scan];if(prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]){strend=s.strstart+MAX_MATCH;do{}while(prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&prev===_win[++scan]&&scans.lookahead){s.match_length=s.lookahead}}}if(s.match_length>=MIN_MATCH){bflush=trees._tr_tally(s,1,s.match_length-MIN_MATCH);s.lookahead-=s.match_length;s.strstart+=s.match_length;s.match_length=0}else{bflush=trees._tr_tally(s,0,s.window[s.strstart]);s.lookahead--;s.strstart++}if(bflush){flush_block_only(s,false);if(s.strm.avail_out===0){return BS_NEED_MORE}}}s.insert=0;if(flush===Z_FINISH){flush_block_only(s,true);if(s.strm.avail_out===0){return BS_FINISH_STARTED}return BS_FINISH_DONE}if(s.last_lit){flush_block_only(s,false);if(s.strm.avail_out===0){return BS_NEED_MORE}}return BS_BLOCK_DONE}function deflate_huff(s,flush){var bflush;for(;;){if(s.lookahead===0){fill_window(s);if(s.lookahead===0){if(flush===Z_NO_FLUSH){return BS_NEED_MORE}break}}s.match_length=0;bflush=trees._tr_tally(s,0,s.window[s.strstart]);s.lookahead--;s.strstart++;if(bflush){flush_block_only(s,false);if(s.strm.avail_out===0){return BS_NEED_MORE}}}s.insert=0;if(flush===Z_FINISH){flush_block_only(s,true);if(s.strm.avail_out===0){return BS_FINISH_STARTED}return BS_FINISH_DONE}if(s.last_lit){flush_block_only(s,false);if(s.strm.avail_out===0){return BS_NEED_MORE}}return BS_BLOCK_DONE}function Config(good_length,max_lazy,nice_length,max_chain,func){this.good_length=good_length;this.max_lazy=max_lazy;this.nice_length=nice_length;this.max_chain=max_chain;this.func=func}var configuration_table;configuration_table=[new Config(0,0,0,0,deflate_stored),new Config(4,4,8,4,deflate_fast),new Config(4,5,16,8,deflate_fast),new Config(4,6,32,32,deflate_fast),new Config(4,4,16,16,deflate_slow),new Config(8,16,32,32,deflate_slow),new Config(8,16,128,128,deflate_slow),new Config(8,32,128,256,deflate_slow),new Config(32,128,258,1024,deflate_slow),new Config(32,258,258,4096,deflate_slow)];function lm_init(s){s.window_size=2*s.w_size;zero(s.head);s.max_lazy_match=configuration_table[s.level].max_lazy;s.good_match=configuration_table[s.level].good_length;s.nice_match=configuration_table[s.level].nice_length;s.max_chain_length=configuration_table[s.level].max_chain;s.strstart=0;s.block_start=0;s.lookahead=0;s.insert=0;s.match_length=s.prev_length=MIN_MATCH-1;s.match_available=0;s.ins_h=0}function DeflateState(){this.strm=null;this.status=0;this.pending_buf=null;this.pending_buf_size=0;this.pending_out=0;this.pending=0;this.wrap=0;this.gzhead=null;this.gzindex=0;this.method=Z_DEFLATED;this.last_flush=-1;this.w_size=0;this.w_bits=0;this.w_mask=0;this.window=null;this.window_size=0;this.prev=null;this.head=null;this.ins_h=0;this.hash_size=0;this.hash_bits=0;this.hash_mask=0;this.hash_shift=0;this.block_start=0;this.match_length=0;this.prev_match=0;this.match_available=0;this.strstart=0;this.match_start=0;this.lookahead=0;this.prev_length=0;this.max_chain_length=0;this.max_lazy_match=0;this.level=0;this.strategy=0;this.good_match=0;this.nice_match=0;this.dyn_ltree=new utils.Buf16(HEAP_SIZE*2);this.dyn_dtree=new utils.Buf16((2*D_CODES+1)*2);this.bl_tree=new utils.Buf16((2*BL_CODES+1)*2);zero(this.dyn_ltree);zero(this.dyn_dtree);zero(this.bl_tree);this.l_desc=null;this.d_desc=null;this.bl_desc=null;this.bl_count=new utils.Buf16(MAX_BITS+1);this.heap=new utils.Buf16(2*L_CODES+1);zero(this.heap);this.heap_len=0;this.heap_max=0;this.depth=new utils.Buf16(2*L_CODES+1);zero(this.depth);this.l_buf=0;this.lit_bufsize=0;this.last_lit=0;this.d_buf=0;this.opt_len=0;this.static_len=0;this.matches=0;this.insert=0;this.bi_buf=0;this.bi_valid=0}function deflateResetKeep(strm){var s;if(!strm||!strm.state){return err(strm,Z_STREAM_ERROR)}strm.total_in=strm.total_out=0;strm.data_type=Z_UNKNOWN;s=strm.state;s.pending=0;s.pending_out=0;if(s.wrap<0){s.wrap=-s.wrap}s.status=s.wrap?INIT_STATE:BUSY_STATE;strm.adler=s.wrap===2?0:1;s.last_flush=Z_NO_FLUSH;trees._tr_init(s);return Z_OK}function deflateReset(strm){var ret=deflateResetKeep(strm);if(ret===Z_OK){lm_init(strm.state)}return ret}function deflateSetHeader(strm,head){if(!strm||!strm.state){return Z_STREAM_ERROR}if(strm.state.wrap!==2){return Z_STREAM_ERROR}strm.state.gzhead=head;return Z_OK}function deflateInit2(strm,level,method,windowBits,memLevel,strategy){if(!strm){return Z_STREAM_ERROR}var wrap=1;if(level===Z_DEFAULT_COMPRESSION){level=6}if(windowBits<0){wrap=0;windowBits=-windowBits}else if(windowBits>15){wrap=2;windowBits-=16}if(memLevel<1||memLevel>MAX_MEM_LEVEL||method!==Z_DEFLATED||windowBits<8||windowBits>15||level<0||level>9||strategy<0||strategy>Z_FIXED){return err(strm,Z_STREAM_ERROR)}if(windowBits===8){windowBits=9}var s=new DeflateState;strm.state=s;s.strm=strm;s.wrap=wrap;s.gzhead=null;s.w_bits=windowBits;s.w_size=1<Z_BLOCK||flush<0){return strm?err(strm,Z_STREAM_ERROR):Z_STREAM_ERROR}s=strm.state;if(!strm.output||!strm.input&&strm.avail_in!==0||s.status===FINISH_STATE&&flush!==Z_FINISH){return err(strm,strm.avail_out===0?Z_BUF_ERROR:Z_STREAM_ERROR)}s.strm=strm;old_flush=s.last_flush;s.last_flush=flush;if(s.status===INIT_STATE){if(s.wrap===2){strm.adler=0;put_byte(s,31);put_byte(s,139);put_byte(s,8);if(!s.gzhead){put_byte(s,0);put_byte(s,0);put_byte(s,0);put_byte(s,0);put_byte(s,0);put_byte(s,s.level===9?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0);put_byte(s,OS_CODE);s.status=BUSY_STATE}else{put_byte(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(!s.gzhead.extra?0:4)+(!s.gzhead.name?0:8)+(!s.gzhead.comment?0:16));put_byte(s,s.gzhead.time&255);put_byte(s,s.gzhead.time>>8&255);put_byte(s,s.gzhead.time>>16&255);put_byte(s,s.gzhead.time>>24&255);put_byte(s,s.level===9?2:s.strategy>=Z_HUFFMAN_ONLY||s.level<2?4:0);put_byte(s,s.gzhead.os&255);if(s.gzhead.extra&&s.gzhead.extra.length){put_byte(s,s.gzhead.extra.length&255);put_byte(s,s.gzhead.extra.length>>8&255)}if(s.gzhead.hcrc){strm.adler=crc32(strm.adler,s.pending_buf,s.pending,0)}s.gzindex=0;s.status=EXTRA_STATE}}else{var header=Z_DEFLATED+(s.w_bits-8<<4)<<8;var level_flags=-1;if(s.strategy>=Z_HUFFMAN_ONLY||s.level<2){level_flags=0}else if(s.level<6){level_flags=1}else if(s.level===6){level_flags=2}else{level_flags=3}header|=level_flags<<6;if(s.strstart!==0){header|=PRESET_DICT}header+=31-header%31;s.status=BUSY_STATE;putShortMSB(s,header);if(s.strstart!==0){putShortMSB(s,strm.adler>>>16);putShortMSB(s,strm.adler&65535)}strm.adler=1}}if(s.status===EXTRA_STATE){if(s.gzhead.extra){beg=s.pending;while(s.gzindex<(s.gzhead.extra.length&65535)){if(s.pending===s.pending_buf_size){if(s.gzhead.hcrc&&s.pending>beg){strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)}flush_pending(strm);beg=s.pending;if(s.pending===s.pending_buf_size){break}}put_byte(s,s.gzhead.extra[s.gzindex]&255);s.gzindex++}if(s.gzhead.hcrc&&s.pending>beg){strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)}if(s.gzindex===s.gzhead.extra.length){s.gzindex=0;s.status=NAME_STATE}}else{s.status=NAME_STATE}}if(s.status===NAME_STATE){if(s.gzhead.name){beg=s.pending;do{if(s.pending===s.pending_buf_size){if(s.gzhead.hcrc&&s.pending>beg){strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)}flush_pending(strm);beg=s.pending;if(s.pending===s.pending_buf_size){val=1;break}}if(s.gzindexbeg){strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)}if(val===0){s.gzindex=0;s.status=COMMENT_STATE}}else{s.status=COMMENT_STATE}}if(s.status===COMMENT_STATE){if(s.gzhead.comment){beg=s.pending;do{if(s.pending===s.pending_buf_size){if(s.gzhead.hcrc&&s.pending>beg){strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)}flush_pending(strm);beg=s.pending;if(s.pending===s.pending_buf_size){val=1;break}}if(s.gzindexbeg){strm.adler=crc32(strm.adler,s.pending_buf,s.pending-beg,beg)}if(val===0){s.status=HCRC_STATE}}else{s.status=HCRC_STATE}}if(s.status===HCRC_STATE){if(s.gzhead.hcrc){if(s.pending+2>s.pending_buf_size){flush_pending(strm)}if(s.pending+2<=s.pending_buf_size){put_byte(s,strm.adler&255);put_byte(s,strm.adler>>8&255);strm.adler=0;s.status=BUSY_STATE}}else{s.status=BUSY_STATE}}if(s.pending!==0){flush_pending(strm);if(strm.avail_out===0){s.last_flush=-1;return Z_OK}}else if(strm.avail_in===0&&rank(flush)<=rank(old_flush)&&flush!==Z_FINISH){return err(strm,Z_BUF_ERROR)}if(s.status===FINISH_STATE&&strm.avail_in!==0){return err(strm,Z_BUF_ERROR)}if(strm.avail_in!==0||s.lookahead!==0||flush!==Z_NO_FLUSH&&s.status!==FINISH_STATE){var bstate=s.strategy===Z_HUFFMAN_ONLY?deflate_huff(s,flush):s.strategy===Z_RLE?deflate_rle(s,flush):configuration_table[s.level].func(s,flush);if(bstate===BS_FINISH_STARTED||bstate===BS_FINISH_DONE){s.status=FINISH_STATE}if(bstate===BS_NEED_MORE||bstate===BS_FINISH_STARTED){if(strm.avail_out===0){s.last_flush=-1}return Z_OK}if(bstate===BS_BLOCK_DONE){if(flush===Z_PARTIAL_FLUSH){trees._tr_align(s)}else if(flush!==Z_BLOCK){trees._tr_stored_block(s,0,0,false);if(flush===Z_FULL_FLUSH){zero(s.head);if(s.lookahead===0){s.strstart=0;s.block_start=0;s.insert=0}}}flush_pending(strm);if(strm.avail_out===0){s.last_flush=-1;return Z_OK}}}if(flush!==Z_FINISH){return Z_OK}if(s.wrap<=0){return Z_STREAM_END}if(s.wrap===2){put_byte(s,strm.adler&255);put_byte(s,strm.adler>>8&255);put_byte(s,strm.adler>>16&255);put_byte(s,strm.adler>>24&255);put_byte(s,strm.total_in&255);put_byte(s,strm.total_in>>8&255);put_byte(s,strm.total_in>>16&255);put_byte(s,strm.total_in>>24&255)}else{putShortMSB(s,strm.adler>>>16);putShortMSB(s,strm.adler&65535)}flush_pending(strm);if(s.wrap>0){s.wrap=-s.wrap}return s.pending!==0?Z_OK:Z_STREAM_END}function deflateEnd(strm){var status;if(!strm||!strm.state){return Z_STREAM_ERROR}status=strm.state.status;if(status!==INIT_STATE&&status!==EXTRA_STATE&&status!==NAME_STATE&&status!==COMMENT_STATE&&status!==HCRC_STATE&&status!==BUSY_STATE&&status!==FINISH_STATE){return err(strm,Z_STREAM_ERROR)}strm.state=null;return status===BUSY_STATE?err(strm,Z_DATA_ERROR):Z_OK}function deflateSetDictionary(strm,dictionary){var dictLength=dictionary.length;var s;var str,n;var wrap;var avail;var next;var input;var tmpDict;if(!strm||!strm.state){return Z_STREAM_ERROR}s=strm.state;wrap=s.wrap;if(wrap===2||wrap===1&&s.status!==INIT_STATE||s.lookahead){return Z_STREAM_ERROR}if(wrap===1){strm.adler=adler32(strm.adler,dictionary,dictLength,0)}s.wrap=0;if(dictLength>=s.w_size){if(wrap===0){zero(s.head);s.strstart=0;s.block_start=0;s.insert=0}tmpDict=new utils.Buf8(s.w_size);utils.arraySet(tmpDict,dictionary,dictLength-s.w_size,s.w_size,0);dictionary=tmpDict;dictLength=s.w_size}avail=strm.avail_in;next=strm.next_in;input=strm.input;strm.avail_in=dictLength;strm.next_in=0;strm.input=dictionary;fill_window(s);while(s.lookahead>=MIN_MATCH){str=s.strstart;n=s.lookahead-(MIN_MATCH-1);do{s.ins_h=(s.ins_h<=0){buf[len]=0}}var STORED_BLOCK=0;var STATIC_TREES=1;var DYN_TREES=2;var MIN_MATCH=3;var MAX_MATCH=258;var LENGTH_CODES=29;var LITERALS=256;var L_CODES=LITERALS+1+LENGTH_CODES;var D_CODES=30;var BL_CODES=19;var HEAP_SIZE=2*L_CODES+1;var MAX_BITS=15;var Buf_size=16;var MAX_BL_BITS=7;var END_BLOCK=256;var REP_3_6=16;var REPZ_3_10=17;var REPZ_11_138=18;var extra_lbits=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0];var extra_dbits=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];var extra_blbits=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];var bl_order=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];var DIST_CODE_LEN=512;var static_ltree=new Array((L_CODES+2)*2);zero(static_ltree);var static_dtree=new Array(D_CODES*2);zero(static_dtree);var _dist_code=new Array(DIST_CODE_LEN);zero(_dist_code);var _length_code=new Array(MAX_MATCH-MIN_MATCH+1);zero(_length_code);var base_length=new Array(LENGTH_CODES);zero(base_length);var base_dist=new Array(D_CODES);zero(base_dist);function StaticTreeDesc(static_tree,extra_bits,extra_base,elems,max_length){this.static_tree=static_tree;this.extra_bits=extra_bits;this.extra_base=extra_base;this.elems=elems;this.max_length=max_length;this.has_stree=static_tree&&static_tree.length}var static_l_desc;var static_d_desc;var static_bl_desc;function TreeDesc(dyn_tree,stat_desc){this.dyn_tree=dyn_tree;this.max_code=0;this.stat_desc=stat_desc}function d_code(dist){return dist<256?_dist_code[dist]:_dist_code[256+(dist>>>7)]}function put_short(s,w){s.pending_buf[s.pending++]=w&255;s.pending_buf[s.pending++]=w>>>8&255}function send_bits(s,value,length){if(s.bi_valid>Buf_size-length){s.bi_buf|=value<>Buf_size-s.bi_valid;s.bi_valid+=length-Buf_size}else{s.bi_buf|=value<>>=1;res<<=1}while(--len>0);return res>>>1}function bi_flush(s){if(s.bi_valid===16){put_short(s,s.bi_buf);s.bi_buf=0;s.bi_valid=0}else if(s.bi_valid>=8){s.pending_buf[s.pending++]=s.bi_buf&255;s.bi_buf>>=8;s.bi_valid-=8}}function gen_bitlen(s,desc){var tree=desc.dyn_tree;var max_code=desc.max_code;var stree=desc.stat_desc.static_tree;var has_stree=desc.stat_desc.has_stree;var extra=desc.stat_desc.extra_bits;var base=desc.stat_desc.extra_base;var max_length=desc.stat_desc.max_length;var h;var n,m;var bits;var xbits;var f;var overflow=0;for(bits=0;bits<=MAX_BITS;bits++){s.bl_count[bits]=0}tree[s.heap[s.heap_max]*2+1]=0;for(h=s.heap_max+1;hmax_length){bits=max_length;overflow++}tree[n*2+1]=bits;if(n>max_code){continue}s.bl_count[bits]++;xbits=0;if(n>=base){xbits=extra[n-base]}f=tree[n*2];s.opt_len+=f*(bits+xbits);if(has_stree){s.static_len+=f*(stree[n*2+1]+xbits)}}if(overflow===0){return}do{bits=max_length-1;while(s.bl_count[bits]===0){bits--}s.bl_count[bits]--;s.bl_count[bits+1]+=2;s.bl_count[max_length]--;overflow-=2}while(overflow>0);for(bits=max_length;bits!==0;bits--){n=s.bl_count[bits];while(n!==0){m=s.heap[--h];if(m>max_code){continue}if(tree[m*2+1]!==bits){s.opt_len+=(bits-tree[m*2+1])*tree[m*2];tree[m*2+1]=bits}n--}}}function gen_codes(tree,max_code,bl_count){var next_code=new Array(MAX_BITS+1);var code=0;var bits;var n;for(bits=1;bits<=MAX_BITS;bits++){next_code[bits]=code=code+bl_count[bits-1]<<1}for(n=0;n<=max_code;n++){var len=tree[n*2+1];if(len===0){continue}tree[n*2]=bi_reverse(next_code[len]++,len)}}function tr_static_init(){var n;var bits;var length;var code;var dist;var bl_count=new Array(MAX_BITS+1);length=0;for(code=0;code>=7;for(;code8){put_short(s,s.bi_buf)}else if(s.bi_valid>0){s.pending_buf[s.pending++]=s.bi_buf}s.bi_buf=0;s.bi_valid=0}function copy_block(s,buf,len,header){bi_windup(s);if(header){put_short(s,len);put_short(s,~len)}utils.arraySet(s.pending_buf,s.window,buf,len,s.pending);s.pending+=len}function smaller(tree,n,m,depth){var _n2=n*2;var _m2=m*2;return tree[_n2]>1;n>=1;n--){pqdownheap(s,tree,n)}node=elems;do{n=s.heap[1];s.heap[1]=s.heap[s.heap_len--];pqdownheap(s,tree,1);m=s.heap[1];s.heap[--s.heap_max]=n;s.heap[--s.heap_max]=m;tree[node*2]=tree[n*2]+tree[m*2];s.depth[node]=(s.depth[n]>=s.depth[m]?s.depth[n]:s.depth[m])+1;tree[n*2+1]=tree[m*2+1]=node;s.heap[1]=node++;pqdownheap(s,tree,1)}while(s.heap_len>=2);s.heap[--s.heap_max]=s.heap[1];gen_bitlen(s,desc);gen_codes(tree,max_code,s.bl_count)}function scan_tree(s,tree,max_code){var n;var prevlen=-1;var curlen;var nextlen=tree[0*2+1];var count=0;var max_count=7;var min_count=4;if(nextlen===0){max_count=138;min_count=3}tree[(max_code+1)*2+1]=65535;for(n=0;n<=max_code;n++){curlen=nextlen;nextlen=tree[(n+1)*2+1];if(++count=3;max_blindex--){if(s.bl_tree[bl_order[max_blindex]*2+1]!==0){break}}s.opt_len+=3*(max_blindex+1)+5+5+4;return max_blindex}function send_all_trees(s,lcodes,dcodes,blcodes){var rank;send_bits(s,lcodes-257,5);send_bits(s,dcodes-1,5);send_bits(s,blcodes-4,4);for(rank=0;rank>>=1){if(black_mask&1&&s.dyn_ltree[n*2]!==0){return Z_BINARY}}if(s.dyn_ltree[9*2]!==0||s.dyn_ltree[10*2]!==0||s.dyn_ltree[13*2]!==0){return Z_TEXT}for(n=32;n0){if(s.strm.data_type===Z_UNKNOWN){s.strm.data_type=detect_data_type(s)}build_tree(s,s.l_desc);build_tree(s,s.d_desc);max_blindex=build_bl_tree(s);opt_lenb=s.opt_len+3+7>>>3;static_lenb=s.static_len+3+7>>>3;if(static_lenb<=opt_lenb){opt_lenb=static_lenb}}else{opt_lenb=static_lenb=stored_len+5}if(stored_len+4<=opt_lenb&&buf!==-1){_tr_stored_block(s,buf,stored_len,last)}else if(s.strategy===Z_FIXED||static_lenb===opt_lenb){send_bits(s,(STATIC_TREES<<1)+(last?1:0),3);compress_block(s,static_ltree,static_dtree)}else{send_bits(s,(DYN_TREES<<1)+(last?1:0),3);send_all_trees(s,s.l_desc.max_code+1,s.d_desc.max_code+1,max_blindex+1);compress_block(s,s.dyn_ltree,s.dyn_dtree)}init_block(s);if(last){bi_windup(s)}}function _tr_tally(s,dist,lc){s.pending_buf[s.d_buf+s.last_lit*2]=dist>>>8&255;s.pending_buf[s.d_buf+s.last_lit*2+1]=dist&255;s.pending_buf[s.l_buf+s.last_lit]=lc&255;s.last_lit++;if(dist===0){s.dyn_ltree[lc*2]++}else{s.matches++;dist--;s.dyn_ltree[(_length_code[lc]+LITERALS+1)*2]++;s.dyn_dtree[d_code(dist)*2]++}return s.last_lit===s.lit_bufsize-1}exports._tr_init=_tr_init;exports._tr_stored_block=_tr_stored_block;exports._tr_flush_block=_tr_flush_block;exports._tr_tally=_tr_tally;exports._tr_align=_tr_align},{"../utils/common":2}],9:[function(require,module,exports){"use strict";function ZStream(){this.input=null;this.next_in=0;this.avail_in=0;this.total_in=0;this.output=null;this.next_out=0;this.avail_out=0;this.total_out=0;this.msg="";this.state=null;this.data_type=2;this.adler=0}module.exports=ZStream},{}],10:[function(require,module,exports){var compressGzip=require("pako/lib/deflate").gzip;function highlighter(document,options){function sendSnippet(snippet){function executor(resolve,reject){var xhr=new XMLHttpRequest;xhr.open("POST",encodeURI("https://api.photon.sh/snippets"));xhr.setRequestHeader("Authorization","Token "+options.apiKey);xhr.setRequestHeader("Content-Type","text/html");xhr.setRequestHeader("Content-Encoding","gzip");xhr.setRequestHeader("Library","javascript");xhr.onload=function(){if(xhr.status===200&&xhr.responseText){var div=document.createElement("div");div.innerHTML=xhr.responseText;snippet.parentNode.parentNode.replaceChild(div.firstChild,snippet.parentNode);resolve()}else if(xhr.status>=400){var error;try{error=xhr.responseText}catch(err){error=JSON.stringify({error:{type:"unknown_error",message:"Unknown error."}})}reject(new Error(error))}};xhr.onerror=function(){reject(new Error(JSON.stringify({error:{type:"unknown_error",message:"Unknown error."}})))};xhr.send(compressGzip(snippet.outerHTML))}return typeof Promise==="function"?new Promise(executor):executor(function(){},function(err){throw err})}var snippets=document.querySelectorAll("pre code[class*=language-], pre code[class*=lang-], pre samp[class*=language-], pre samp[class*=lang-]");return Array.prototype.slice.call(snippets).filter(function(snippet){return snippet.textContent!==""}).map(sendSnippet)}module.exports=highlighter},{"pako/lib/deflate":1}],11:[function(require,module,exports){var highlighter=require("./highlighter");function photon(){var apiKey="";return{setup:function setup(options){if(options===undefined){options={}}if(typeof options!=="object"||options===null){throw new Error("Setup's first argument (options) must be an object.")}if(options.apiKey){apiKey=options.apiKey}},highlight:function highlight(options){if(options===undefined){options={}}if(typeof options!=="object"||options===null){throw new Error("Highlight's second argument (options) must be an object.")}if(apiKey===""&&options.apiKey===undefined){throw new Error("Missing API key.")}return highlighter(document,{apiKey:options.apiKey||apiKey})}}}module.exports=photon()},{"./highlighter":10}]},{},[11])(11)}); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "photon-js", 3 | "description": "photon-js is a JavaScript library for Photon", 4 | "version": "0.1.3", 5 | "main": "./dist/photon.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/photonsh/photon-js.git" 9 | }, 10 | "license": "MIT", 11 | "author": "Photon (https://photon.sh)", 12 | "bugs": { 13 | "url": "https://github.com/photonsh/photon-js/issues" 14 | }, 15 | "keywords": [ 16 | "photon", 17 | "highlight", 18 | "syntax", 19 | "browser" 20 | ], 21 | "homepage": "https://photon.sh", 22 | "dependencies": { 23 | "pako": "^1.0.5" 24 | }, 25 | "devDependencies": { 26 | "browserify": "^14.3.0", 27 | "uglify-js": "^3.0.7" 28 | }, 29 | "scripts": { 30 | "build:main": "browserify -s photon -o ./dist/photon.js ./src/index.js", 31 | "build:min": "uglifyjs -o ./dist/photon.min.js ./dist/photon.js", 32 | "build": "npm run build:main && npm run build:min;" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/highlighter.js: -------------------------------------------------------------------------------- 1 | var compressGzip = require('pako/lib/deflate').gzip; 2 | 3 | function highlighter(document, options) { 4 | function sendSnippet(snippet) { 5 | function executor(resolve, reject) { 6 | var xhr = new XMLHttpRequest(); 7 | xhr.open('POST', encodeURI('https://api.photon.sh/snippets')); 8 | xhr.setRequestHeader('Authorization', 'Token ' + options.apiKey); 9 | xhr.setRequestHeader('Content-Type', 'text/html'); 10 | xhr.setRequestHeader('Content-Encoding', 'gzip'); 11 | xhr.setRequestHeader('Library', 'javascript'); 12 | 13 | xhr.onload = function () { 14 | if (xhr.status === 200 && xhr.responseText) { 15 | var div = document.createElement('div'); 16 | div.innerHTML = xhr.responseText; 17 | snippet.parentNode.parentNode.replaceChild(div.firstChild, snippet.parentNode); 18 | resolve(); 19 | } else if (xhr.status >= 400) { 20 | var error; 21 | try { 22 | error = xhr.responseText; 23 | } catch (err) { 24 | error = JSON.stringify({ error: { type: 'unknown_error', message: 'Unknown error.' } }); 25 | } 26 | 27 | reject(new Error(error)); 28 | } 29 | } 30 | 31 | xhr.onerror = function () { 32 | reject(new Error(JSON.stringify({ error: { type: 'unknown_error', message: 'Unknown error.' } }))); 33 | } 34 | 35 | xhr.send(compressGzip(snippet.outerHTML)); 36 | } 37 | 38 | return (typeof Promise === 'function') ? new Promise(executor) : executor(function () {}, function (err) { throw(err); }); 39 | } 40 | 41 | var snippets = document.querySelectorAll('pre code[class*=language-], pre code[class*=lang-], pre samp[class*=language-], pre samp[class*=lang-]'); 42 | 43 | return Array.prototype.slice.call(snippets) 44 | .filter(function(snippet) { return (snippet.textContent !== '') }) 45 | .map(sendSnippet) 46 | } 47 | 48 | module.exports = highlighter 49 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | var highlighter = require('./highlighter'); 2 | 3 | function photon() { 4 | var apiKey = ''; 5 | 6 | return { 7 | setup: function setup(options) { 8 | if (options === undefined) { 9 | options = {}; 10 | } 11 | 12 | if (typeof options !== 'object' || options === null) { 13 | throw new Error('Setup\'s first argument (options) must be an object.'); 14 | } 15 | 16 | if (options.apiKey) { 17 | apiKey = options.apiKey; 18 | } 19 | }, 20 | highlight: function highlight(options) { 21 | if (options === undefined) { 22 | options = {}; 23 | } 24 | 25 | if (typeof options !== 'object' || options === null) { 26 | throw new Error('Highlight\'s second argument (options) must be an object.'); 27 | } 28 | 29 | if (apiKey === '' && options.apiKey === undefined) { 30 | throw new Error('Missing API key.'); 31 | } 32 | 33 | return highlighter(document, { apiKey: options.apiKey || apiKey }); 34 | } 35 | } 36 | } 37 | 38 | module.exports = photon() 39 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | JSONStream@^1.0.3: 6 | version "1.3.1" 7 | resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.1.tgz#707f761e01dae9e16f1bcf93703b78c70966579a" 8 | dependencies: 9 | jsonparse "^1.2.0" 10 | through ">=2.2.7 <3" 11 | 12 | acorn@^4.0.3: 13 | version "4.0.11" 14 | resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0" 15 | 16 | array-filter@~0.0.0: 17 | version "0.0.1" 18 | resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-0.0.1.tgz#7da8cf2e26628ed732803581fd21f67cacd2eeec" 19 | 20 | array-map@~0.0.0: 21 | version "0.0.0" 22 | resolved "https://registry.yarnpkg.com/array-map/-/array-map-0.0.0.tgz#88a2bab73d1cf7bcd5c1b118a003f66f665fa662" 23 | 24 | array-reduce@~0.0.0: 25 | version "0.0.0" 26 | resolved "https://registry.yarnpkg.com/array-reduce/-/array-reduce-0.0.0.tgz#173899d3ffd1c7d9383e4479525dbe278cab5f2b" 27 | 28 | asn1.js@^4.0.0: 29 | version "4.9.1" 30 | resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.9.1.tgz#48ba240b45a9280e94748990ba597d216617fd40" 31 | dependencies: 32 | bn.js "^4.0.0" 33 | inherits "^2.0.1" 34 | minimalistic-assert "^1.0.0" 35 | 36 | assert@^1.4.0: 37 | version "1.4.1" 38 | resolved "https://registry.yarnpkg.com/assert/-/assert-1.4.1.tgz#99912d591836b5a6f5b345c0f07eefc08fc65d91" 39 | dependencies: 40 | util "0.10.3" 41 | 42 | astw@^2.0.0: 43 | version "2.2.0" 44 | resolved "https://registry.yarnpkg.com/astw/-/astw-2.2.0.tgz#7bd41784d32493987aeb239b6b4e1c57a873b917" 45 | dependencies: 46 | acorn "^4.0.3" 47 | 48 | balanced-match@^0.4.1: 49 | version "0.4.2" 50 | resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" 51 | 52 | base64-js@^1.0.2: 53 | version "1.2.0" 54 | resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1" 55 | 56 | bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0: 57 | version "4.11.6" 58 | resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215" 59 | 60 | brace-expansion@^1.1.7: 61 | version "1.1.7" 62 | resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59" 63 | dependencies: 64 | balanced-match "^0.4.1" 65 | concat-map "0.0.1" 66 | 67 | brorand@^1.0.1: 68 | version "1.1.0" 69 | resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" 70 | 71 | browser-pack@^6.0.1: 72 | version "6.0.2" 73 | resolved "https://registry.yarnpkg.com/browser-pack/-/browser-pack-6.0.2.tgz#f86cd6cef4f5300c8e63e07a4d512f65fbff4531" 74 | dependencies: 75 | JSONStream "^1.0.3" 76 | combine-source-map "~0.7.1" 77 | defined "^1.0.0" 78 | through2 "^2.0.0" 79 | umd "^3.0.0" 80 | 81 | browser-resolve@^1.11.0, browser-resolve@^1.7.0: 82 | version "1.11.2" 83 | resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.2.tgz#8ff09b0a2c421718a1051c260b32e48f442938ce" 84 | dependencies: 85 | resolve "1.1.7" 86 | 87 | browserify-aes@^1.0.0, browserify-aes@^1.0.4: 88 | version "1.0.6" 89 | resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-1.0.6.tgz#5e7725dbdef1fd5930d4ebab48567ce451c48a0a" 90 | dependencies: 91 | buffer-xor "^1.0.2" 92 | cipher-base "^1.0.0" 93 | create-hash "^1.1.0" 94 | evp_bytestokey "^1.0.0" 95 | inherits "^2.0.1" 96 | 97 | browserify-cipher@^1.0.0: 98 | version "1.0.0" 99 | resolved "https://registry.yarnpkg.com/browserify-cipher/-/browserify-cipher-1.0.0.tgz#9988244874bf5ed4e28da95666dcd66ac8fc363a" 100 | dependencies: 101 | browserify-aes "^1.0.4" 102 | browserify-des "^1.0.0" 103 | evp_bytestokey "^1.0.0" 104 | 105 | browserify-des@^1.0.0: 106 | version "1.0.0" 107 | resolved "https://registry.yarnpkg.com/browserify-des/-/browserify-des-1.0.0.tgz#daa277717470922ed2fe18594118a175439721dd" 108 | dependencies: 109 | cipher-base "^1.0.1" 110 | des.js "^1.0.0" 111 | inherits "^2.0.1" 112 | 113 | browserify-rsa@^4.0.0: 114 | version "4.0.1" 115 | resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.0.1.tgz#21e0abfaf6f2029cf2fafb133567a701d4135524" 116 | dependencies: 117 | bn.js "^4.1.0" 118 | randombytes "^2.0.1" 119 | 120 | browserify-sign@^4.0.0: 121 | version "4.0.4" 122 | resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.0.4.tgz#aa4eb68e5d7b658baa6bf6a57e630cbd7a93d298" 123 | dependencies: 124 | bn.js "^4.1.1" 125 | browserify-rsa "^4.0.0" 126 | create-hash "^1.1.0" 127 | create-hmac "^1.1.2" 128 | elliptic "^6.0.0" 129 | inherits "^2.0.1" 130 | parse-asn1 "^5.0.0" 131 | 132 | browserify-zlib@~0.1.2: 133 | version "0.1.4" 134 | resolved "https://registry.yarnpkg.com/browserify-zlib/-/browserify-zlib-0.1.4.tgz#bb35f8a519f600e0fa6b8485241c979d0141fb2d" 135 | dependencies: 136 | pako "~0.2.0" 137 | 138 | browserify@^14.3.0: 139 | version "14.3.0" 140 | resolved "https://registry.yarnpkg.com/browserify/-/browserify-14.3.0.tgz#fd003a2386ac1aec127f097885a3cc6373b745c4" 141 | dependencies: 142 | JSONStream "^1.0.3" 143 | assert "^1.4.0" 144 | browser-pack "^6.0.1" 145 | browser-resolve "^1.11.0" 146 | browserify-zlib "~0.1.2" 147 | buffer "^5.0.2" 148 | cached-path-relative "^1.0.0" 149 | concat-stream "~1.5.1" 150 | console-browserify "^1.1.0" 151 | constants-browserify "~1.0.0" 152 | crypto-browserify "^3.0.0" 153 | defined "^1.0.0" 154 | deps-sort "^2.0.0" 155 | domain-browser "~1.1.0" 156 | duplexer2 "~0.1.2" 157 | events "~1.1.0" 158 | glob "^7.1.0" 159 | has "^1.0.0" 160 | htmlescape "^1.1.0" 161 | https-browserify "^1.0.0" 162 | inherits "~2.0.1" 163 | insert-module-globals "^7.0.0" 164 | labeled-stream-splicer "^2.0.0" 165 | module-deps "^4.0.8" 166 | os-browserify "~0.1.1" 167 | parents "^1.0.1" 168 | path-browserify "~0.0.0" 169 | process "~0.11.0" 170 | punycode "^1.3.2" 171 | querystring-es3 "~0.2.0" 172 | read-only-stream "^2.0.0" 173 | readable-stream "^2.0.2" 174 | resolve "^1.1.4" 175 | shasum "^1.0.0" 176 | shell-quote "^1.6.1" 177 | stream-browserify "^2.0.0" 178 | stream-http "^2.0.0" 179 | string_decoder "~0.10.0" 180 | subarg "^1.0.0" 181 | syntax-error "^1.1.1" 182 | through2 "^2.0.0" 183 | timers-browserify "^1.0.1" 184 | tty-browserify "~0.0.0" 185 | url "~0.11.0" 186 | util "~0.10.1" 187 | vm-browserify "~0.0.1" 188 | xtend "^4.0.0" 189 | 190 | buffer-shims@~1.0.0: 191 | version "1.0.0" 192 | resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51" 193 | 194 | buffer-xor@^1.0.2: 195 | version "1.0.3" 196 | resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" 197 | 198 | buffer@^5.0.2: 199 | version "5.0.6" 200 | resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.0.6.tgz#2ea669f7eec0b6eda05b08f8b5ff661b28573588" 201 | dependencies: 202 | base64-js "^1.0.2" 203 | ieee754 "^1.1.4" 204 | 205 | builtin-status-codes@^3.0.0: 206 | version "3.0.0" 207 | resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8" 208 | 209 | cached-path-relative@^1.0.0: 210 | version "1.0.1" 211 | resolved "https://registry.yarnpkg.com/cached-path-relative/-/cached-path-relative-1.0.1.tgz#d09c4b52800aa4c078e2dd81a869aac90d2e54e7" 212 | 213 | cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: 214 | version "1.0.3" 215 | resolved "https://registry.yarnpkg.com/cipher-base/-/cipher-base-1.0.3.tgz#eeabf194419ce900da3018c207d212f2a6df0a07" 216 | dependencies: 217 | inherits "^2.0.1" 218 | 219 | combine-source-map@~0.7.1: 220 | version "0.7.2" 221 | resolved "https://registry.yarnpkg.com/combine-source-map/-/combine-source-map-0.7.2.tgz#0870312856b307a87cc4ac486f3a9a62aeccc09e" 222 | dependencies: 223 | convert-source-map "~1.1.0" 224 | inline-source-map "~0.6.0" 225 | lodash.memoize "~3.0.3" 226 | source-map "~0.5.3" 227 | 228 | commander@~2.9.0: 229 | version "2.9.0" 230 | resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" 231 | dependencies: 232 | graceful-readlink ">= 1.0.0" 233 | 234 | concat-map@0.0.1: 235 | version "0.0.1" 236 | resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" 237 | 238 | concat-stream@~1.5.0, concat-stream@~1.5.1: 239 | version "1.5.2" 240 | resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.5.2.tgz#708978624d856af41a5a741defdd261da752c266" 241 | dependencies: 242 | inherits "~2.0.1" 243 | readable-stream "~2.0.0" 244 | typedarray "~0.0.5" 245 | 246 | console-browserify@^1.1.0: 247 | version "1.1.0" 248 | resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10" 249 | dependencies: 250 | date-now "^0.1.4" 251 | 252 | constants-browserify@~1.0.0: 253 | version "1.0.0" 254 | resolved "https://registry.yarnpkg.com/constants-browserify/-/constants-browserify-1.0.0.tgz#c20b96d8c617748aaf1c16021760cd27fcb8cb75" 255 | 256 | convert-source-map@~1.1.0: 257 | version "1.1.3" 258 | resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.1.3.tgz#4829c877e9fe49b3161f3bf3673888e204699860" 259 | 260 | core-util-is@~1.0.0: 261 | version "1.0.2" 262 | resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" 263 | 264 | create-ecdh@^4.0.0: 265 | version "4.0.0" 266 | resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.0.tgz#888c723596cdf7612f6498233eebd7a35301737d" 267 | dependencies: 268 | bn.js "^4.1.0" 269 | elliptic "^6.0.0" 270 | 271 | create-hash@^1.1.0, create-hash@^1.1.1, create-hash@^1.1.2: 272 | version "1.1.3" 273 | resolved "https://registry.yarnpkg.com/create-hash/-/create-hash-1.1.3.tgz#606042ac8b9262750f483caddab0f5819172d8fd" 274 | dependencies: 275 | cipher-base "^1.0.1" 276 | inherits "^2.0.1" 277 | ripemd160 "^2.0.0" 278 | sha.js "^2.4.0" 279 | 280 | create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4: 281 | version "1.1.6" 282 | resolved "https://registry.yarnpkg.com/create-hmac/-/create-hmac-1.1.6.tgz#acb9e221a4e17bdb076e90657c42b93e3726cf06" 283 | dependencies: 284 | cipher-base "^1.0.3" 285 | create-hash "^1.1.0" 286 | inherits "^2.0.1" 287 | ripemd160 "^2.0.0" 288 | safe-buffer "^5.0.1" 289 | sha.js "^2.4.8" 290 | 291 | crypto-browserify@^3.0.0: 292 | version "3.11.0" 293 | resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.11.0.tgz#3652a0906ab9b2a7e0c3ce66a408e957a2485522" 294 | dependencies: 295 | browserify-cipher "^1.0.0" 296 | browserify-sign "^4.0.0" 297 | create-ecdh "^4.0.0" 298 | create-hash "^1.1.0" 299 | create-hmac "^1.1.0" 300 | diffie-hellman "^5.0.0" 301 | inherits "^2.0.1" 302 | pbkdf2 "^3.0.3" 303 | public-encrypt "^4.0.0" 304 | randombytes "^2.0.0" 305 | 306 | date-now@^0.1.4: 307 | version "0.1.4" 308 | resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b" 309 | 310 | defined@^1.0.0: 311 | version "1.0.0" 312 | resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693" 313 | 314 | deps-sort@^2.0.0: 315 | version "2.0.0" 316 | resolved "https://registry.yarnpkg.com/deps-sort/-/deps-sort-2.0.0.tgz#091724902e84658260eb910748cccd1af6e21fb5" 317 | dependencies: 318 | JSONStream "^1.0.3" 319 | shasum "^1.0.0" 320 | subarg "^1.0.0" 321 | through2 "^2.0.0" 322 | 323 | des.js@^1.0.0: 324 | version "1.0.0" 325 | resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.0.tgz#c074d2e2aa6a8a9a07dbd61f9a15c2cd83ec8ecc" 326 | dependencies: 327 | inherits "^2.0.1" 328 | minimalistic-assert "^1.0.0" 329 | 330 | detective@^4.0.0: 331 | version "4.5.0" 332 | resolved "https://registry.yarnpkg.com/detective/-/detective-4.5.0.tgz#6e5a8c6b26e6c7a254b1c6b6d7490d98ec91edd1" 333 | dependencies: 334 | acorn "^4.0.3" 335 | defined "^1.0.0" 336 | 337 | diffie-hellman@^5.0.0: 338 | version "5.0.2" 339 | resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.2.tgz#b5835739270cfe26acf632099fded2a07f209e5e" 340 | dependencies: 341 | bn.js "^4.1.0" 342 | miller-rabin "^4.0.0" 343 | randombytes "^2.0.0" 344 | 345 | domain-browser@~1.1.0: 346 | version "1.1.7" 347 | resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc" 348 | 349 | duplexer2@^0.1.2, duplexer2@~0.1.0, duplexer2@~0.1.2: 350 | version "0.1.4" 351 | resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1" 352 | dependencies: 353 | readable-stream "^2.0.2" 354 | 355 | elliptic@^6.0.0: 356 | version "6.4.0" 357 | resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.0.tgz#cac9af8762c85836187003c8dfe193e5e2eae5df" 358 | dependencies: 359 | bn.js "^4.4.0" 360 | brorand "^1.0.1" 361 | hash.js "^1.0.0" 362 | hmac-drbg "^1.0.0" 363 | inherits "^2.0.1" 364 | minimalistic-assert "^1.0.0" 365 | minimalistic-crypto-utils "^1.0.0" 366 | 367 | events@~1.1.0: 368 | version "1.1.1" 369 | resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924" 370 | 371 | evp_bytestokey@^1.0.0: 372 | version "1.0.0" 373 | resolved "https://registry.yarnpkg.com/evp_bytestokey/-/evp_bytestokey-1.0.0.tgz#497b66ad9fef65cd7c08a6180824ba1476b66e53" 374 | dependencies: 375 | create-hash "^1.1.1" 376 | 377 | fs.realpath@^1.0.0: 378 | version "1.0.0" 379 | resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" 380 | 381 | function-bind@^1.0.2: 382 | version "1.1.0" 383 | resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771" 384 | 385 | glob@^7.1.0: 386 | version "7.1.1" 387 | resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" 388 | dependencies: 389 | fs.realpath "^1.0.0" 390 | inflight "^1.0.4" 391 | inherits "2" 392 | minimatch "^3.0.2" 393 | once "^1.3.0" 394 | path-is-absolute "^1.0.0" 395 | 396 | "graceful-readlink@>= 1.0.0": 397 | version "1.0.1" 398 | resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" 399 | 400 | has@^1.0.0: 401 | version "1.0.1" 402 | resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28" 403 | dependencies: 404 | function-bind "^1.0.2" 405 | 406 | hash-base@^2.0.0: 407 | version "2.0.2" 408 | resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-2.0.2.tgz#66ea1d856db4e8a5470cadf6fce23ae5244ef2e1" 409 | dependencies: 410 | inherits "^2.0.1" 411 | 412 | hash.js@^1.0.0, hash.js@^1.0.3: 413 | version "1.0.3" 414 | resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.0.3.tgz#1332ff00156c0a0ffdd8236013d07b77a0451573" 415 | dependencies: 416 | inherits "^2.0.1" 417 | 418 | hmac-drbg@^1.0.0: 419 | version "1.0.1" 420 | resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" 421 | dependencies: 422 | hash.js "^1.0.3" 423 | minimalistic-assert "^1.0.0" 424 | minimalistic-crypto-utils "^1.0.1" 425 | 426 | htmlescape@^1.1.0: 427 | version "1.1.1" 428 | resolved "https://registry.yarnpkg.com/htmlescape/-/htmlescape-1.1.1.tgz#3a03edc2214bca3b66424a3e7959349509cb0351" 429 | 430 | https-browserify@^1.0.0: 431 | version "1.0.0" 432 | resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73" 433 | 434 | ieee754@^1.1.4: 435 | version "1.1.8" 436 | resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4" 437 | 438 | indexof@0.0.1: 439 | version "0.0.1" 440 | resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" 441 | 442 | inflight@^1.0.4: 443 | version "1.0.6" 444 | resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" 445 | dependencies: 446 | once "^1.3.0" 447 | wrappy "1" 448 | 449 | inherits@2, inherits@^2.0.1, inherits@~2.0.1: 450 | version "2.0.3" 451 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" 452 | 453 | inherits@2.0.1: 454 | version "2.0.1" 455 | resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" 456 | 457 | inline-source-map@~0.6.0: 458 | version "0.6.2" 459 | resolved "https://registry.yarnpkg.com/inline-source-map/-/inline-source-map-0.6.2.tgz#f9393471c18a79d1724f863fa38b586370ade2a5" 460 | dependencies: 461 | source-map "~0.5.3" 462 | 463 | insert-module-globals@^7.0.0: 464 | version "7.0.1" 465 | resolved "https://registry.yarnpkg.com/insert-module-globals/-/insert-module-globals-7.0.1.tgz#c03bf4e01cb086d5b5e5ace8ad0afe7889d638c3" 466 | dependencies: 467 | JSONStream "^1.0.3" 468 | combine-source-map "~0.7.1" 469 | concat-stream "~1.5.1" 470 | is-buffer "^1.1.0" 471 | lexical-scope "^1.2.0" 472 | process "~0.11.0" 473 | through2 "^2.0.0" 474 | xtend "^4.0.0" 475 | 476 | is-buffer@^1.1.0: 477 | version "1.1.5" 478 | resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc" 479 | 480 | isarray@~0.0.1: 481 | version "0.0.1" 482 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" 483 | 484 | isarray@~1.0.0: 485 | version "1.0.0" 486 | resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" 487 | 488 | json-stable-stringify@~0.0.0: 489 | version "0.0.1" 490 | resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-0.0.1.tgz#611c23e814db375527df851193db59dd2af27f45" 491 | dependencies: 492 | jsonify "~0.0.0" 493 | 494 | jsonify@~0.0.0: 495 | version "0.0.0" 496 | resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" 497 | 498 | jsonparse@^1.2.0: 499 | version "1.3.1" 500 | resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" 501 | 502 | labeled-stream-splicer@^2.0.0: 503 | version "2.0.0" 504 | resolved "https://registry.yarnpkg.com/labeled-stream-splicer/-/labeled-stream-splicer-2.0.0.tgz#a52e1d138024c00b86b1c0c91f677918b8ae0a59" 505 | dependencies: 506 | inherits "^2.0.1" 507 | isarray "~0.0.1" 508 | stream-splicer "^2.0.0" 509 | 510 | lexical-scope@^1.2.0: 511 | version "1.2.0" 512 | resolved "https://registry.yarnpkg.com/lexical-scope/-/lexical-scope-1.2.0.tgz#fcea5edc704a4b3a8796cdca419c3a0afaf22df4" 513 | dependencies: 514 | astw "^2.0.0" 515 | 516 | lodash.memoize@~3.0.3: 517 | version "3.0.4" 518 | resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-3.0.4.tgz#2dcbd2c287cbc0a55cc42328bd0c736150d53e3f" 519 | 520 | miller-rabin@^4.0.0: 521 | version "4.0.0" 522 | resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.0.tgz#4a62fb1d42933c05583982f4c716f6fb9e6c6d3d" 523 | dependencies: 524 | bn.js "^4.0.0" 525 | brorand "^1.0.1" 526 | 527 | minimalistic-assert@^1.0.0: 528 | version "1.0.0" 529 | resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.0.tgz#702be2dda6b37f4836bcb3f5db56641b64a1d3d3" 530 | 531 | minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: 532 | version "1.0.1" 533 | resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" 534 | 535 | minimatch@^3.0.2: 536 | version "3.0.4" 537 | resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" 538 | dependencies: 539 | brace-expansion "^1.1.7" 540 | 541 | minimist@^1.1.0: 542 | version "1.2.0" 543 | resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" 544 | 545 | module-deps@^4.0.8: 546 | version "4.1.1" 547 | resolved "https://registry.yarnpkg.com/module-deps/-/module-deps-4.1.1.tgz#23215833f1da13fd606ccb8087b44852dcb821fd" 548 | dependencies: 549 | JSONStream "^1.0.3" 550 | browser-resolve "^1.7.0" 551 | cached-path-relative "^1.0.0" 552 | concat-stream "~1.5.0" 553 | defined "^1.0.0" 554 | detective "^4.0.0" 555 | duplexer2 "^0.1.2" 556 | inherits "^2.0.1" 557 | parents "^1.0.0" 558 | readable-stream "^2.0.2" 559 | resolve "^1.1.3" 560 | stream-combiner2 "^1.1.1" 561 | subarg "^1.0.0" 562 | through2 "^2.0.0" 563 | xtend "^4.0.0" 564 | 565 | once@^1.3.0: 566 | version "1.4.0" 567 | resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" 568 | dependencies: 569 | wrappy "1" 570 | 571 | os-browserify@~0.1.1: 572 | version "0.1.2" 573 | resolved "https://registry.yarnpkg.com/os-browserify/-/os-browserify-0.1.2.tgz#49ca0293e0b19590a5f5de10c7f265a617d8fe54" 574 | 575 | pako@^1.0.5: 576 | version "1.0.5" 577 | resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.5.tgz#d2205dfe5b9da8af797e7c163db4d1f84e4600bc" 578 | 579 | pako@~0.2.0: 580 | version "0.2.9" 581 | resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75" 582 | 583 | parents@^1.0.0, parents@^1.0.1: 584 | version "1.0.1" 585 | resolved "https://registry.yarnpkg.com/parents/-/parents-1.0.1.tgz#fedd4d2bf193a77745fe71e371d73c3307d9c751" 586 | dependencies: 587 | path-platform "~0.11.15" 588 | 589 | parse-asn1@^5.0.0: 590 | version "5.1.0" 591 | resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.0.tgz#37c4f9b7ed3ab65c74817b5f2480937fbf97c712" 592 | dependencies: 593 | asn1.js "^4.0.0" 594 | browserify-aes "^1.0.0" 595 | create-hash "^1.1.0" 596 | evp_bytestokey "^1.0.0" 597 | pbkdf2 "^3.0.3" 598 | 599 | path-browserify@~0.0.0: 600 | version "0.0.0" 601 | resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.0.tgz#a0b870729aae214005b7d5032ec2cbbb0fb4451a" 602 | 603 | path-is-absolute@^1.0.0: 604 | version "1.0.1" 605 | resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" 606 | 607 | path-parse@^1.0.5: 608 | version "1.0.5" 609 | resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" 610 | 611 | path-platform@~0.11.15: 612 | version "0.11.15" 613 | resolved "https://registry.yarnpkg.com/path-platform/-/path-platform-0.11.15.tgz#e864217f74c36850f0852b78dc7bf7d4a5721bf2" 614 | 615 | pbkdf2@^3.0.3: 616 | version "3.0.12" 617 | resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.12.tgz#be36785c5067ea48d806ff923288c5f750b6b8a2" 618 | dependencies: 619 | create-hash "^1.1.2" 620 | create-hmac "^1.1.4" 621 | ripemd160 "^2.0.1" 622 | safe-buffer "^5.0.1" 623 | sha.js "^2.4.8" 624 | 625 | process-nextick-args@~1.0.6: 626 | version "1.0.7" 627 | resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3" 628 | 629 | process@~0.11.0: 630 | version "0.11.10" 631 | resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" 632 | 633 | public-encrypt@^4.0.0: 634 | version "4.0.0" 635 | resolved "https://registry.yarnpkg.com/public-encrypt/-/public-encrypt-4.0.0.tgz#39f699f3a46560dd5ebacbca693caf7c65c18cc6" 636 | dependencies: 637 | bn.js "^4.1.0" 638 | browserify-rsa "^4.0.0" 639 | create-hash "^1.1.0" 640 | parse-asn1 "^5.0.0" 641 | randombytes "^2.0.1" 642 | 643 | punycode@1.3.2: 644 | version "1.3.2" 645 | resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" 646 | 647 | punycode@^1.3.2: 648 | version "1.4.1" 649 | resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" 650 | 651 | querystring-es3@~0.2.0: 652 | version "0.2.1" 653 | resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" 654 | 655 | querystring@0.2.0: 656 | version "0.2.0" 657 | resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" 658 | 659 | randombytes@^2.0.0, randombytes@^2.0.1: 660 | version "2.0.3" 661 | resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.0.3.tgz#674c99760901c3c4112771a31e521dc349cc09ec" 662 | 663 | read-only-stream@^2.0.0: 664 | version "2.0.0" 665 | resolved "https://registry.yarnpkg.com/read-only-stream/-/read-only-stream-2.0.0.tgz#2724fd6a8113d73764ac288d4386270c1dbf17f0" 666 | dependencies: 667 | readable-stream "^2.0.2" 668 | 669 | readable-stream@^2.0.2, readable-stream@^2.1.5, readable-stream@^2.2.6: 670 | version "2.2.9" 671 | resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.9.tgz#cf78ec6f4a6d1eb43d26488cac97f042e74b7fc8" 672 | dependencies: 673 | buffer-shims "~1.0.0" 674 | core-util-is "~1.0.0" 675 | inherits "~2.0.1" 676 | isarray "~1.0.0" 677 | process-nextick-args "~1.0.6" 678 | string_decoder "~1.0.0" 679 | util-deprecate "~1.0.1" 680 | 681 | readable-stream@~2.0.0: 682 | version "2.0.6" 683 | resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e" 684 | dependencies: 685 | core-util-is "~1.0.0" 686 | inherits "~2.0.1" 687 | isarray "~1.0.0" 688 | process-nextick-args "~1.0.6" 689 | string_decoder "~0.10.x" 690 | util-deprecate "~1.0.1" 691 | 692 | resolve@1.1.7: 693 | version "1.1.7" 694 | resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" 695 | 696 | resolve@^1.1.3, resolve@^1.1.4: 697 | version "1.3.3" 698 | resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.3.tgz#655907c3469a8680dc2de3a275a8fdd69691f0e5" 699 | dependencies: 700 | path-parse "^1.0.5" 701 | 702 | ripemd160@^2.0.0, ripemd160@^2.0.1: 703 | version "2.0.1" 704 | resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.1.tgz#0f4584295c53a3628af7e6d79aca21ce57d1c6e7" 705 | dependencies: 706 | hash-base "^2.0.0" 707 | inherits "^2.0.1" 708 | 709 | safe-buffer@^5.0.1: 710 | version "5.0.1" 711 | resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7" 712 | 713 | sha.js@^2.4.0, sha.js@^2.4.8, sha.js@~2.4.4: 714 | version "2.4.8" 715 | resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.8.tgz#37068c2c476b6baf402d14a49c67f597921f634f" 716 | dependencies: 717 | inherits "^2.0.1" 718 | 719 | shasum@^1.0.0: 720 | version "1.0.2" 721 | resolved "https://registry.yarnpkg.com/shasum/-/shasum-1.0.2.tgz#e7012310d8f417f4deb5712150e5678b87ae565f" 722 | dependencies: 723 | json-stable-stringify "~0.0.0" 724 | sha.js "~2.4.4" 725 | 726 | shell-quote@^1.6.1: 727 | version "1.6.1" 728 | resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767" 729 | dependencies: 730 | array-filter "~0.0.0" 731 | array-map "~0.0.0" 732 | array-reduce "~0.0.0" 733 | jsonify "~0.0.0" 734 | 735 | source-map@~0.5.1, source-map@~0.5.3: 736 | version "0.5.6" 737 | resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" 738 | 739 | stream-browserify@^2.0.0: 740 | version "2.0.1" 741 | resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db" 742 | dependencies: 743 | inherits "~2.0.1" 744 | readable-stream "^2.0.2" 745 | 746 | stream-combiner2@^1.1.1: 747 | version "1.1.1" 748 | resolved "https://registry.yarnpkg.com/stream-combiner2/-/stream-combiner2-1.1.1.tgz#fb4d8a1420ea362764e21ad4780397bebcb41cbe" 749 | dependencies: 750 | duplexer2 "~0.1.0" 751 | readable-stream "^2.0.2" 752 | 753 | stream-http@^2.0.0: 754 | version "2.7.1" 755 | resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-2.7.1.tgz#546a51741ad5a6b07e9e31b0b10441a917df528a" 756 | dependencies: 757 | builtin-status-codes "^3.0.0" 758 | inherits "^2.0.1" 759 | readable-stream "^2.2.6" 760 | to-arraybuffer "^1.0.0" 761 | xtend "^4.0.0" 762 | 763 | stream-splicer@^2.0.0: 764 | version "2.0.0" 765 | resolved "https://registry.yarnpkg.com/stream-splicer/-/stream-splicer-2.0.0.tgz#1b63be438a133e4b671cc1935197600175910d83" 766 | dependencies: 767 | inherits "^2.0.1" 768 | readable-stream "^2.0.2" 769 | 770 | string_decoder@~0.10.0, string_decoder@~0.10.x: 771 | version "0.10.31" 772 | resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" 773 | 774 | string_decoder@~1.0.0: 775 | version "1.0.0" 776 | resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.0.0.tgz#f06f41157b664d86069f84bdbdc9b0d8ab281667" 777 | dependencies: 778 | buffer-shims "~1.0.0" 779 | 780 | subarg@^1.0.0: 781 | version "1.0.0" 782 | resolved "https://registry.yarnpkg.com/subarg/-/subarg-1.0.0.tgz#f62cf17581e996b48fc965699f54c06ae268b8d2" 783 | dependencies: 784 | minimist "^1.1.0" 785 | 786 | syntax-error@^1.1.1: 787 | version "1.3.0" 788 | resolved "https://registry.yarnpkg.com/syntax-error/-/syntax-error-1.3.0.tgz#1ed9266c4d40be75dc55bf9bb1cb77062bb96ca1" 789 | dependencies: 790 | acorn "^4.0.3" 791 | 792 | through2@^2.0.0: 793 | version "2.0.3" 794 | resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.3.tgz#0004569b37c7c74ba39c43f3ced78d1ad94140be" 795 | dependencies: 796 | readable-stream "^2.1.5" 797 | xtend "~4.0.1" 798 | 799 | "through@>=2.2.7 <3": 800 | version "2.3.8" 801 | resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" 802 | 803 | timers-browserify@^1.0.1: 804 | version "1.4.2" 805 | resolved "https://registry.yarnpkg.com/timers-browserify/-/timers-browserify-1.4.2.tgz#c9c58b575be8407375cb5e2462dacee74359f41d" 806 | dependencies: 807 | process "~0.11.0" 808 | 809 | to-arraybuffer@^1.0.0: 810 | version "1.0.1" 811 | resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43" 812 | 813 | tty-browserify@~0.0.0: 814 | version "0.0.0" 815 | resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" 816 | 817 | typedarray@~0.0.5: 818 | version "0.0.6" 819 | resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" 820 | 821 | uglify-js@^3.0.7: 822 | version "3.0.7" 823 | resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.0.7.tgz#5cca9c14abae2dd60ceccdf7da3c672cc8069cec" 824 | dependencies: 825 | commander "~2.9.0" 826 | source-map "~0.5.1" 827 | 828 | umd@^3.0.0: 829 | version "3.0.1" 830 | resolved "https://registry.yarnpkg.com/umd/-/umd-3.0.1.tgz#8ae556e11011f63c2596708a8837259f01b3d60e" 831 | 832 | url@~0.11.0: 833 | version "0.11.0" 834 | resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1" 835 | dependencies: 836 | punycode "1.3.2" 837 | querystring "0.2.0" 838 | 839 | util-deprecate@~1.0.1: 840 | version "1.0.2" 841 | resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" 842 | 843 | util@0.10.3, util@~0.10.1: 844 | version "0.10.3" 845 | resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9" 846 | dependencies: 847 | inherits "2.0.1" 848 | 849 | vm-browserify@~0.0.1: 850 | version "0.0.4" 851 | resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-0.0.4.tgz#5d7ea45bbef9e4a6ff65f95438e0a87c357d5a73" 852 | dependencies: 853 | indexof "0.0.1" 854 | 855 | wrappy@1: 856 | version "1.0.2" 857 | resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" 858 | 859 | xtend@^4.0.0, xtend@~4.0.1: 860 | version "4.0.1" 861 | resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" 862 | --------------------------------------------------------------------------------