{“ast”:null,“code”:“'use strict'; // (C) 1995-2013 Jean-loup Gailly and Mark Adlern// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsinn//n// This software is provided 'as-is', without any express or impliedn// warranty. In no event will the authors be held liable for any damagesn// arising from the use of this software.n//n// Permission is granted to anyone to use this software for any purpose,n// including commercial applications, and to alter it and redistribute itn// freely, subject to the following restrictions:n//n// 1. The origin of this software must not be misrepresented; you must notn// claim that you wrote the original software. If you use this softwaren// in a product, an acknowledgment in the product documentation would ben// appreciated but is not required.n// 2. Altered source versions must be plainly marked as such, and must not ben// misrepresented as being the original software.n// 3. This notice may not be removed or altered from any source distribution.nnvar utils = require('../utils/common');nnvar MAXBITS = 15;nvar ENOUGH_LENS = 852;nvar ENOUGH_DISTS = 592; //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);nnvar CODES = 0;nvar LENS = 1;nvar DISTS = 2;nvar lbase = [n/* Length codes 257..285 base */n3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0];nvar lext = [n/* Length codes 257..285 extra */n16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78];nvar dbase = [n/* Distance codes 0..29 base */n1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0];nvar dext = [n/* Distance codes 0..29 extra */n16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64];nnmodule.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts) {n var bits = opts.bits; //here = opts.here; /* table entry for duplication */nn var len = 0;n /* a code's length in bits */nn var sym = 0;n /* index of code symbols */nn var min = 0,n max = 0;n /* minimum and maximum code lengths */nn var root = 0;n /* number of index bits for root table */nn var curr = 0;n /* number of index bits for current table */nn var drop = 0;n /* code bits to drop for sub-table */nn var left = 0;n /* number of prefix codes available */nn var used = 0;n /* code entries in table used */nn var huff = 0;n /* Huffman code */nn var incr;n /* for incrementing code, index */nn var fill;n /* index for replicating entries */nn var low;n /* low bits for current root entry */nn var mask;n /* mask for low root bits */nn var next;n /* next available space in table */nn var base = null;n /* base value table to use */nn var base_index = 0; // var shoextra; /* extra bits table to use */nn var end;n /* use base and extra for symbol > end */nn var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */nn var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */nn var extra = null;n var extra_index = 0;n var here_bits, here_op, here_val;n /*n Process a set of code lengths to create a canonical Huffman code. Then code lengths are lens. Each length corresponds to then symbols 0..codes-1. The Huffman code is generated by first sorting then symbols by length from short to long, and retaining the symbol ordern for codes with equal lengths. Then the code starts with all zero bitsn for the first code of the shortest length, and the codes are integern increments for the same length, and zeros are appended as the lengthn increases. For the deflate format, these bits are stored backwardsn from their more natural integer increment ordering, and so when then decoding tables are built in the large loop below, the integer codesn are incremented backwards.n This routine assumes, but does not check, that all of the entries inn lens[] are in the range 0..MAXBITS. The caller must assure this.n 1..MAXBITS is interpreted as that code length. zero means that thatn symbol does not occur in this code.n The codes are sorted by computing a count of codes for each length,n creating from that a table of starting indices for each length in then sorted table, and then entering the symbols in order in the sortedn table. The sorted table is work[], with that space being provided byn the caller.n The length counts are used for other purposes as well, i.e. findingn the minimum and maximum length codes, determining if there are anyn codes at all, checking for a valid set of lengths, and looking aheadn at length counts to determine sub-table sizes when building then decoding tables.n */nn /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */nn for (len = 0; len <= MAXBITS; len++) {n count = 0;n }nn for (sym = 0; sym < codes; sym++) {n count[lens[lens_index + sym]]++;n }n /* bound code lengths, force root to be within code lengths */nnn root = bits;nn for (max = MAXBITS; max >= 1; max–) {n if (count !== 0) {n break;n }n }nn if (root > max) {n root = max;n }nn if (max === 0) {n /* no symbols to code at all */n //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */n //table.bits[opts.table_index] = 1; //here.bits = (var char)1;n //table.val[opts.table_index++] = 0; //here.val = (var short)0;n table = 1 << 24 | 64 << 16 | 0; //table.op[opts.table_index] = 64;n //table.bits[opts.table_index] = 1;n //table.val[opts.table_index++] = 0;nn table = 1 << 24 | 64 << 16 | 0;n opts.bits = 1;n return 0;n /* no symbols, but wait for decoding to report error */n }nn for (min = 1; min < max; min++) {n if (count !== 0) {n break;n }n }nn if (root < min) {n root = min;n }n /* check for an over-subscribed or incomplete set of lengths */nnn left = 1;nn for (len = 1; len <= MAXBITS; len++) {n left <<= 1;n left -= count;nn if (left < 0) {n return -1;n }n /* over-subscribed */nn }nn if (left > 0 && (type === CODES || max !== 1)) {n return -1;n /* incomplete set */n }n /* generate offsets into symbol table for each length for sorting */nnn offs = 0;nn for (len = 1; len < MAXBITS; len++) {n offs[len + 1] = offs + count;n }n /* sort symbols by length, by symbol order within each length */nnn for (sym = 0; sym < codes; sym++) {n if (lens[lens_index + sym] !== 0) {n work[offs[lens[lens_index + sym]]++] = sym;n }n }n /*n Create and fill in decoding tables. In this loop, the table beingn filled is at next and has curr index bits. The code being used is huffn with length len. That code is converted to an index by dropping dropn bits off of the bottom. For codes where len is less than drop + curr,n those top drop + curr - len bits are incremented through all values ton fill the table with replicated entries.n root is the number of index bits for the root table. When len exceedsn root, sub-tables are created pointed to by the root entry with an indexn of the low root bits of huff. This is saved in low to check for when an new sub-table should be started. drop is zero when the root table isn being filled, and drop is root when sub-tables are being filled.n When a new sub-table is needed, it is necessary to look ahead in then code lengths to determine what size sub-table is needed. The lengthn counts are used for this, and so count[] is decremented as codes aren entered in the tables.n used keeps track of how many table entries have been allocated from then provided *table space. It is checked for LENS and DIST tables againstn the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes inn the initial root table size constants. See the comments in inftrees.hn for more information.n sym increments through all symbols, and the loop terminates whenn all codes of length max, i.e. all codes, have been processed. Thisn routine permits incomplete codes, so another loop after this one fillsn in the rest of the decoding tables with invalid code markers.n */nn /* set up for code type */n // poor man optimization - use if-else instead of switch,n // to avoid deopts in old v8nnn if (type === CODES) {n base = extra = work;n /* dummy value–not used */nn end = 19;n } else if (type === LENS) {n base = lbase;n base_index -= 257;n extra = lext;n extra_index -= 257;n end = 256;n } else {n /* DISTS */n base = dbase;n extra = dext;n end = -1;n }n /* initialize opts for loop */nnn huff = 0;n /* starting code */nn sym = 0;n /* starting code symbol */nn len = min;n /* starting code length */nn next = table_index;n /* current table to fill in */nn curr = root;n /* current table index bits */nn drop = 0;n /* current bits to drop from code for index */nn low = -1;n /* trigger new sub-table when len > root */nn used = 1 << root;n /* use root table entries */nn mask = used - 1;n /* mask for comparing low */nn /* check available table space */nn if (type === LENS && used > ENOUGH_LENS || type === DISTS && used > ENOUGH_DISTS) {n return 1;n }n /* process all codes and make table entries */nnn for (;;) {n /* create table entry */n here_bits = len - drop;nn if (work < end) {n here_op = 0;n here_val = work;n } else if (work > end) {n here_op = extra[extra_index + work];n here_val = base[base_index + work];n } else {n here_op = 32 + 64;n /* end of block */nn here_val = 0;n }n /* replicate for those indices with low len bits equal to huff */nnn incr = 1 << len - drop;n fill = 1 << curr;n min = fill;n /* save offset to next table */nn do {n fill -= incr;n table[next + (huff >> drop) + fill] = here_bits << 24 | here_op << 16 | here_val | 0;n } while (fill !== 0);n /* backwards increment the len-bit code huff */nnn incr = 1 << len - 1;nn while (huff & incr) {n incr >>= 1;n }nn if (incr !== 0) {n huff &= incr - 1;n huff += incr;n } else {n huff = 0;n }n /* go to next symbol, update count, len */nnn sym++;nn if (–count === 0) {n if (len === max) {n break;n }nn len = lens[lens_index + work];n }n /* create new sub-table if needed */nnn if (len > root && (huff & mask) !== low) {n /* if first time, transition to sub-tables */n if (drop === 0) {n drop = root;n }n /* increment past last table */nnn next += min;n /* here min is 1 << curr */nn /* determine length of next table */nn curr = len - drop;n left = 1 << curr;nn while (curr + drop < max) {n left -= count[curr + drop];nn if (left <= 0) {n break;n }nn curr++;n left <<= 1;n }n /* check for enough space */nnn used += 1 << curr;nn if (type === LENS && used > ENOUGH_LENS || type === DISTS && used > ENOUGH_DISTS) {n return 1;n }n /* point entry in root table to sub-table */nnn low = huff & mask;n /*table.op = curr;n table.bits = root;n table.val = next - opts.table_index;*/nn table = root << 24 | curr << 16 | next - table_index | 0;n }n }n /* fill in remaining table entry if code is incomplete (guaranteed to haven at most one remaining entry, since if the code is incomplete, then maximum code length that was allowed to get this far is one bit) */nnn if (huff !== 0) {n //table.op[next + huff] = 64; /* invalid code marker */n //table.bits[next + huff] = len - drop;n //table.val[next + huff] = 0;n table[next + huff] = len - drop << 24 | 64 << 16 | 0;n }n /* set return parameters */n //opts.table_index += used;nnn opts.bits = root;n return 0;n};”,“map”:null,“metadata”:{},“sourceType”:“module”}