@helloao/cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions.d.ts +57 -0
- package/actions.js +262 -0
- package/cli.d.ts +2 -0
- package/cli.js +139 -0
- package/db.d.ts +110 -0
- package/db.js +754 -0
- package/downloads.d.ts +2 -0
- package/downloads.js +12 -0
- package/files.d.ts +56 -0
- package/files.js +232 -0
- package/index.d.ts +8 -0
- package/index.js +38 -0
- package/migrations/20240420231455_initial/migration.sql +66 -0
- package/migrations/20240623183848_add_book_order/migration.sql +26 -0
- package/migrations/20240629194121_add_chapter_links/migration.sql +45 -0
- package/migrations/20240629194513_add_chapter_content/migration.sql +30 -0
- package/migrations/20240705221833_remove_unused_columns/migration.sql +27 -0
- package/migrations/20240711173108_add_chapter_audio/migration.sql +13 -0
- package/migrations/20240724212651_add_hashing/migration.sql +25 -0
- package/node_modules/@zip.js/zip.js/LICENSE +28 -0
- package/node_modules/@zip.js/zip.js/README.md +173 -0
- package/node_modules/@zip.js/zip.js/deno.json +8 -0
- package/node_modules/@zip.js/zip.js/dist/README.md +28 -0
- package/node_modules/@zip.js/zip.js/dist/z-worker-fflate.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/z-worker-pako.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/z-worker.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/zip-fs-full.js +11935 -0
- package/node_modules/@zip.js/zip.js/dist/zip-fs-full.min.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/zip-fs.js +6079 -0
- package/node_modules/@zip.js/zip.js/dist/zip-fs.min.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/zip-full.js +9463 -0
- package/node_modules/@zip.js/zip.js/dist/zip-full.min.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/zip-no-worker-deflate.min.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/zip-no-worker-inflate.min.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/zip-no-worker.min.js +1 -0
- package/node_modules/@zip.js/zip.js/dist/zip.js +5240 -0
- package/node_modules/@zip.js/zip.js/dist/zip.min.js +1 -0
- package/node_modules/@zip.js/zip.js/index-fflate.js +82 -0
- package/node_modules/@zip.js/zip.js/index.cjs +11927 -0
- package/node_modules/@zip.js/zip.js/index.d.ts +2048 -0
- package/node_modules/@zip.js/zip.js/index.js +87 -0
- package/node_modules/@zip.js/zip.js/index.min.js +1 -0
- package/node_modules/@zip.js/zip.js/lib/core/codec-pool.js +127 -0
- package/node_modules/@zip.js/zip.js/lib/core/codec-worker.js +348 -0
- package/node_modules/@zip.js/zip.js/lib/core/configuration.js +127 -0
- package/node_modules/@zip.js/zip.js/lib/core/constants.js +114 -0
- package/node_modules/@zip.js/zip.js/lib/core/io.js +749 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/aes-crypto-stream.js +326 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/codec-stream.js +154 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/crc32.js +63 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/deflate.js +2063 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/inflate.js +2167 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/sjcl.js +827 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/common-crypto.js +55 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/crc32-stream.js +56 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/stream-adapter.js +55 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/zip-crypto-stream.js +162 -0
- package/node_modules/@zip.js/zip.js/lib/core/streams/zip-entry-stream.js +165 -0
- package/node_modules/@zip.js/zip.js/lib/core/util/cp437-decode.js +48 -0
- package/node_modules/@zip.js/zip.js/lib/core/util/decode-text.js +43 -0
- package/node_modules/@zip.js/zip.js/lib/core/util/default-mime-type.js +38 -0
- package/node_modules/@zip.js/zip.js/lib/core/util/encode-text.js +48 -0
- package/node_modules/@zip.js/zip.js/lib/core/util/mime-type.js +1639 -0
- package/node_modules/@zip.js/zip.js/lib/core/util/stream-codec-shim.js +91 -0
- package/node_modules/@zip.js/zip.js/lib/core/z-worker-core.js +176 -0
- package/node_modules/@zip.js/zip.js/lib/core/zip-entry.js +86 -0
- package/node_modules/@zip.js/zip.js/lib/core/zip-fs-core.js +865 -0
- package/node_modules/@zip.js/zip.js/lib/core/zip-reader.js +757 -0
- package/node_modules/@zip.js/zip.js/lib/core/zip-writer.js +1186 -0
- package/node_modules/@zip.js/zip.js/lib/z-worker-bootstrap-fflate.js +40 -0
- package/node_modules/@zip.js/zip.js/lib/z-worker-bootstrap-pako.js +39 -0
- package/node_modules/@zip.js/zip.js/lib/z-worker-fflate.js +40 -0
- package/node_modules/@zip.js/zip.js/lib/z-worker-inline-template.js +42 -0
- package/node_modules/@zip.js/zip.js/lib/z-worker-inline.js +1 -0
- package/node_modules/@zip.js/zip.js/lib/z-worker.js +38 -0
- package/node_modules/@zip.js/zip.js/lib/zip-data-uri.js +53 -0
- package/node_modules/@zip.js/zip.js/lib/zip-fflate-shim.js +37 -0
- package/node_modules/@zip.js/zip.js/lib/zip-fs.js +53 -0
- package/node_modules/@zip.js/zip.js/lib/zip-full-fflate.js +53 -0
- package/node_modules/@zip.js/zip.js/lib/zip-full.js +54 -0
- package/node_modules/@zip.js/zip.js/lib/zip-no-worker-deflate.js +42 -0
- package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate-deflate.js +42 -0
- package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate-inflate.js +42 -0
- package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate.js +43 -0
- package/node_modules/@zip.js/zip.js/lib/zip-no-worker-inflate.js +42 -0
- package/node_modules/@zip.js/zip.js/lib/zip-no-worker.js +44 -0
- package/node_modules/@zip.js/zip.js/lib/zip.js +52 -0
- package/node_modules/@zip.js/zip.js/package.json +86 -0
- package/package.json +43 -0
- package/prisma-gen/default.d.ts +1 -0
- package/prisma-gen/default.js +1 -0
- package/prisma-gen/edge.d.ts +1 -0
- package/prisma-gen/edge.js +242 -0
- package/prisma-gen/index-browser.js +236 -0
- package/prisma-gen/index.d.ts +13248 -0
- package/prisma-gen/index.js +265 -0
- package/prisma-gen/runtime/edge-esm.js +28 -0
- package/prisma-gen/runtime/edge.js +28 -0
- package/prisma-gen/runtime/index-browser.d.ts +365 -0
- package/prisma-gen/runtime/index-browser.js +13 -0
- package/prisma-gen/runtime/library.d.ts +3168 -0
- package/prisma-gen/runtime/library.js +140 -0
- package/prisma-gen/runtime/wasm.js +29 -0
- package/prisma-gen/wasm.d.ts +1 -0
- package/prisma-gen/wasm.js +236 -0
- package/s3.d.ts +14 -0
- package/s3.js +76 -0
- package/schema.prisma +154 -0
- package/uploads.d.ts +54 -0
- package/uploads.js +141 -0
|
@@ -0,0 +1,2167 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in
|
|
12
|
+
the documentation and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. The names of the authors may not be used to endorse or promote products
|
|
15
|
+
derived from this software without specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
18
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
20
|
+
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
22
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
23
|
+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
26
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.
|
|
31
|
+
* JZlib is based on zlib-1.1.3, so all credit should go authors
|
|
32
|
+
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
|
|
33
|
+
* and contributors of zlib.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// deno-lint-ignore-file no-this-alias prefer-const
|
|
37
|
+
|
|
38
|
+
// Global
|
|
39
|
+
|
|
40
|
+
const MAX_BITS = 15;
|
|
41
|
+
|
|
42
|
+
const Z_OK = 0;
|
|
43
|
+
const Z_STREAM_END = 1;
|
|
44
|
+
const Z_NEED_DICT = 2;
|
|
45
|
+
const Z_STREAM_ERROR = -2;
|
|
46
|
+
const Z_DATA_ERROR = -3;
|
|
47
|
+
const Z_MEM_ERROR = -4;
|
|
48
|
+
const Z_BUF_ERROR = -5;
|
|
49
|
+
|
|
50
|
+
const inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff,
|
|
51
|
+
0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff];
|
|
52
|
+
|
|
53
|
+
const MANY = 1440;
|
|
54
|
+
|
|
55
|
+
// JZlib version : "1.0.2"
|
|
56
|
+
const Z_NO_FLUSH = 0;
|
|
57
|
+
const Z_FINISH = 4;
|
|
58
|
+
|
|
59
|
+
// InfTree
|
|
60
|
+
const fixed_bl = 9;
|
|
61
|
+
const fixed_bd = 5;
|
|
62
|
+
|
|
63
|
+
const fixed_tl = [96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0,
|
|
64
|
+
0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40,
|
|
65
|
+
0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13,
|
|
66
|
+
0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60,
|
|
67
|
+
0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7,
|
|
68
|
+
35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8,
|
|
69
|
+
26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80,
|
|
70
|
+
7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0,
|
|
71
|
+
8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0,
|
|
72
|
+
8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97,
|
|
73
|
+
0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210,
|
|
74
|
+
81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117,
|
|
75
|
+
0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154,
|
|
76
|
+
84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83,
|
|
77
|
+
0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230,
|
|
78
|
+
80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139,
|
|
79
|
+
0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174,
|
|
80
|
+
0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111,
|
|
81
|
+
0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9,
|
|
82
|
+
193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8,
|
|
83
|
+
120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8,
|
|
84
|
+
227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8,
|
|
85
|
+
92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9,
|
|
86
|
+
249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8,
|
|
87
|
+
130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9,
|
|
88
|
+
181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8,
|
|
89
|
+
102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9,
|
|
90
|
+
221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0,
|
|
91
|
+
8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9,
|
|
92
|
+
147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8,
|
|
93
|
+
85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9,
|
|
94
|
+
235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8,
|
|
95
|
+
141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9,
|
|
96
|
+
167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8,
|
|
97
|
+
107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9,
|
|
98
|
+
207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8,
|
|
99
|
+
127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255];
|
|
100
|
+
const fixed_td = [80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5,
|
|
101
|
+
8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5,
|
|
102
|
+
24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577];
|
|
103
|
+
|
|
104
|
+
// Tables for deflate from PKZIP's appnote.txt.
|
|
105
|
+
const cplens = [ // Copy lengths for literal codes 257..285
|
|
106
|
+
3, 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];
|
|
107
|
+
|
|
108
|
+
// see note #13 above about 258
|
|
109
|
+
const cplext = [ // Extra bits for literal codes 257..285
|
|
110
|
+
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, 112, 112 // 112==invalid
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
const cpdist = [ // Copy offsets for distance codes 0..29
|
|
114
|
+
1, 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];
|
|
115
|
+
|
|
116
|
+
const cpdext = [ // Extra bits for distance codes
|
|
117
|
+
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];
|
|
118
|
+
|
|
119
|
+
// If BMAX needs to be larger than 16, then h and x[] should be uLong.
|
|
120
|
+
const BMAX = 15; // maximum bit length of any code
|
|
121
|
+
|
|
122
|
+
function InfTree() {
|
|
123
|
+
const that = this;
|
|
124
|
+
|
|
125
|
+
let hn; // hufts used in space
|
|
126
|
+
let v; // work area for huft_build
|
|
127
|
+
let c; // bit length count table
|
|
128
|
+
let r; // table entry for structure assignment
|
|
129
|
+
let u; // table stack
|
|
130
|
+
let x; // bit offsets, then code stack
|
|
131
|
+
|
|
132
|
+
function huft_build(b, // code lengths in bits (all assumed <=
|
|
133
|
+
// BMAX)
|
|
134
|
+
bindex, n, // number of codes (assumed <= 288)
|
|
135
|
+
s, // number of simple-valued codes (0..s-1)
|
|
136
|
+
d, // list of base values for non-simple codes
|
|
137
|
+
e, // list of extra bits for non-simple codes
|
|
138
|
+
t, // result: starting table
|
|
139
|
+
m, // maximum lookup bits, returns actual
|
|
140
|
+
hp,// space for trees
|
|
141
|
+
hn,// hufts used in space
|
|
142
|
+
v // working area: values in order of bit length
|
|
143
|
+
) {
|
|
144
|
+
// Given a list of code lengths and a maximum table size, make a set of
|
|
145
|
+
// tables to decode that set of codes. Return Z_OK on success,
|
|
146
|
+
// Z_BUF_ERROR
|
|
147
|
+
// if the given code set is incomplete (the tables are still built in
|
|
148
|
+
// this
|
|
149
|
+
// case), Z_DATA_ERROR if the input is invalid (an over-subscribed set
|
|
150
|
+
// of
|
|
151
|
+
// lengths), or Z_MEM_ERROR if not enough memory.
|
|
152
|
+
|
|
153
|
+
let a; // counter for codes of length k
|
|
154
|
+
let f; // i repeats in table every f entries
|
|
155
|
+
let g; // maximum code length
|
|
156
|
+
let h; // table level
|
|
157
|
+
let i; // counter, current code
|
|
158
|
+
let j; // counter
|
|
159
|
+
let k; // number of bits in current code
|
|
160
|
+
let l; // bits per table (returned in m)
|
|
161
|
+
let mask; // (1 << w) - 1, to avoid cc -O bug on HP
|
|
162
|
+
let p; // pointer into c[], b[], or v[]
|
|
163
|
+
let q; // points to current table
|
|
164
|
+
let w; // bits before this table == (l * h)
|
|
165
|
+
let xp; // pointer into x
|
|
166
|
+
let y; // number of dummy codes added
|
|
167
|
+
let z; // number of entries in current table
|
|
168
|
+
|
|
169
|
+
// Generate counts for each bit length
|
|
170
|
+
|
|
171
|
+
p = 0;
|
|
172
|
+
i = n;
|
|
173
|
+
do {
|
|
174
|
+
c[b[bindex + p]]++;
|
|
175
|
+
p++;
|
|
176
|
+
i--; // assume all entries <= BMAX
|
|
177
|
+
} while (i !== 0);
|
|
178
|
+
|
|
179
|
+
if (c[0] == n) { // null input--all zero length codes
|
|
180
|
+
t[0] = -1;
|
|
181
|
+
m[0] = 0;
|
|
182
|
+
return Z_OK;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Find minimum and maximum length, bound *m by those
|
|
186
|
+
l = m[0];
|
|
187
|
+
for (j = 1; j <= BMAX; j++)
|
|
188
|
+
if (c[j] !== 0)
|
|
189
|
+
break;
|
|
190
|
+
k = j; // minimum code length
|
|
191
|
+
if (l < j) {
|
|
192
|
+
l = j;
|
|
193
|
+
}
|
|
194
|
+
for (i = BMAX; i !== 0; i--) {
|
|
195
|
+
if (c[i] !== 0)
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
g = i; // maximum code length
|
|
199
|
+
if (l > i) {
|
|
200
|
+
l = i;
|
|
201
|
+
}
|
|
202
|
+
m[0] = l;
|
|
203
|
+
|
|
204
|
+
// Adjust last length count to fill out codes, if needed
|
|
205
|
+
for (y = 1 << j; j < i; j++, y <<= 1) {
|
|
206
|
+
if ((y -= c[j]) < 0) {
|
|
207
|
+
return Z_DATA_ERROR;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if ((y -= c[i]) < 0) {
|
|
211
|
+
return Z_DATA_ERROR;
|
|
212
|
+
}
|
|
213
|
+
c[i] += y;
|
|
214
|
+
|
|
215
|
+
// Generate starting offsets into the value table for each length
|
|
216
|
+
x[1] = j = 0;
|
|
217
|
+
p = 1;
|
|
218
|
+
xp = 2;
|
|
219
|
+
while (--i !== 0) { // note that i == g from above
|
|
220
|
+
x[xp] = (j += c[p]);
|
|
221
|
+
xp++;
|
|
222
|
+
p++;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Make a table of values in order of bit lengths
|
|
226
|
+
i = 0;
|
|
227
|
+
p = 0;
|
|
228
|
+
do {
|
|
229
|
+
if ((j = b[bindex + p]) !== 0) {
|
|
230
|
+
v[x[j]++] = i;
|
|
231
|
+
}
|
|
232
|
+
p++;
|
|
233
|
+
} while (++i < n);
|
|
234
|
+
n = x[g]; // set n to length of v
|
|
235
|
+
|
|
236
|
+
// Generate the Huffman codes and for each, make the table entries
|
|
237
|
+
x[0] = i = 0; // first Huffman code is zero
|
|
238
|
+
p = 0; // grab values in bit order
|
|
239
|
+
h = -1; // no tables yet--level -1
|
|
240
|
+
w = -l; // bits decoded == (l * h)
|
|
241
|
+
u[0] = 0; // just to keep compilers happy
|
|
242
|
+
q = 0; // ditto
|
|
243
|
+
z = 0; // ditto
|
|
244
|
+
|
|
245
|
+
// go through the bit lengths (k already is bits in shortest code)
|
|
246
|
+
for (; k <= g; k++) {
|
|
247
|
+
a = c[k];
|
|
248
|
+
while (a-- !== 0) {
|
|
249
|
+
// here i is the Huffman code of length k bits for value *p
|
|
250
|
+
// make tables up to required level
|
|
251
|
+
while (k > w + l) {
|
|
252
|
+
h++;
|
|
253
|
+
w += l; // previous table always l bits
|
|
254
|
+
// compute minimum size table less than or equal to l bits
|
|
255
|
+
z = g - w;
|
|
256
|
+
z = (z > l) ? l : z; // table size upper limit
|
|
257
|
+
if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table
|
|
258
|
+
// too few codes for
|
|
259
|
+
// k-w bit table
|
|
260
|
+
f -= a + 1; // deduct codes from patterns left
|
|
261
|
+
xp = k;
|
|
262
|
+
if (j < z) {
|
|
263
|
+
while (++j < z) { // try smaller tables up to z bits
|
|
264
|
+
if ((f <<= 1) <= c[++xp])
|
|
265
|
+
break; // enough codes to use up j bits
|
|
266
|
+
f -= c[xp]; // else deduct codes from patterns
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
z = 1 << j; // table entries for j-bit table
|
|
271
|
+
|
|
272
|
+
// allocate new table
|
|
273
|
+
if (hn[0] + z > MANY) { // (note: doesn't matter for fixed)
|
|
274
|
+
return Z_DATA_ERROR; // overflow of MANY
|
|
275
|
+
}
|
|
276
|
+
u[h] = q = /* hp+ */hn[0]; // DEBUG
|
|
277
|
+
hn[0] += z;
|
|
278
|
+
|
|
279
|
+
// connect to last table, if there is one
|
|
280
|
+
if (h !== 0) {
|
|
281
|
+
x[h] = i; // save pattern for backing up
|
|
282
|
+
r[0] = /* (byte) */j; // bits in this table
|
|
283
|
+
r[1] = /* (byte) */l; // bits to dump before this table
|
|
284
|
+
j = i >>> (w - l);
|
|
285
|
+
r[2] = /* (int) */(q - u[h - 1] - j); // offset to this table
|
|
286
|
+
hp.set(r, (u[h - 1] + j) * 3);
|
|
287
|
+
// to
|
|
288
|
+
// last
|
|
289
|
+
// table
|
|
290
|
+
} else {
|
|
291
|
+
t[0] = q; // first table is returned result
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// set up table entry in r
|
|
296
|
+
r[1] = /* (byte) */(k - w);
|
|
297
|
+
if (p >= n) {
|
|
298
|
+
r[0] = 128 + 64; // out of values--invalid code
|
|
299
|
+
} else if (v[p] < s) {
|
|
300
|
+
r[0] = /* (byte) */(v[p] < 256 ? 0 : 32 + 64); // 256 is
|
|
301
|
+
// end-of-block
|
|
302
|
+
r[2] = v[p++]; // simple code is just the value
|
|
303
|
+
} else {
|
|
304
|
+
r[0] = /* (byte) */(e[v[p] - s] + 16 + 64); // non-simple--look
|
|
305
|
+
// up in lists
|
|
306
|
+
r[2] = d[v[p++] - s];
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// fill code-like entries with r
|
|
310
|
+
f = 1 << (k - w);
|
|
311
|
+
for (j = i >>> w; j < z; j += f) {
|
|
312
|
+
hp.set(r, (q + j) * 3);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// backwards increment the k-bit code i
|
|
316
|
+
for (j = 1 << (k - 1); (i & j) !== 0; j >>>= 1) {
|
|
317
|
+
i ^= j;
|
|
318
|
+
}
|
|
319
|
+
i ^= j;
|
|
320
|
+
|
|
321
|
+
// backup over finished tables
|
|
322
|
+
mask = (1 << w) - 1; // needed on HP, cc -O bug
|
|
323
|
+
while ((i & mask) != x[h]) {
|
|
324
|
+
h--; // don't need to update q
|
|
325
|
+
w -= l;
|
|
326
|
+
mask = (1 << w) - 1;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// Return Z_BUF_ERROR if we were given an incomplete table
|
|
331
|
+
return y !== 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function initWorkArea(vsize) {
|
|
335
|
+
let i;
|
|
336
|
+
if (!hn) {
|
|
337
|
+
hn = []; // []; //new Array(1);
|
|
338
|
+
v = []; // new Array(vsize);
|
|
339
|
+
c = new Int32Array(BMAX + 1); // new Array(BMAX + 1);
|
|
340
|
+
r = []; // new Array(3);
|
|
341
|
+
u = new Int32Array(BMAX); // new Array(BMAX);
|
|
342
|
+
x = new Int32Array(BMAX + 1); // new Array(BMAX + 1);
|
|
343
|
+
}
|
|
344
|
+
if (v.length < vsize) {
|
|
345
|
+
v = []; // new Array(vsize);
|
|
346
|
+
}
|
|
347
|
+
for (i = 0; i < vsize; i++) {
|
|
348
|
+
v[i] = 0;
|
|
349
|
+
}
|
|
350
|
+
for (i = 0; i < BMAX + 1; i++) {
|
|
351
|
+
c[i] = 0;
|
|
352
|
+
}
|
|
353
|
+
for (i = 0; i < 3; i++) {
|
|
354
|
+
r[i] = 0;
|
|
355
|
+
}
|
|
356
|
+
// for(int i=0; i<BMAX; i++){u[i]=0;}
|
|
357
|
+
u.set(c.subarray(0, BMAX), 0);
|
|
358
|
+
// for(int i=0; i<BMAX+1; i++){x[i]=0;}
|
|
359
|
+
x.set(c.subarray(0, BMAX + 1), 0);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
that.inflate_trees_bits = function (c, // 19 code lengths
|
|
363
|
+
bb, // bits tree desired/actual depth
|
|
364
|
+
tb, // bits tree result
|
|
365
|
+
hp, // space for trees
|
|
366
|
+
z // for messages
|
|
367
|
+
) {
|
|
368
|
+
let result;
|
|
369
|
+
initWorkArea(19);
|
|
370
|
+
hn[0] = 0;
|
|
371
|
+
result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
|
|
372
|
+
|
|
373
|
+
if (result == Z_DATA_ERROR) {
|
|
374
|
+
z.msg = "oversubscribed dynamic bit lengths tree";
|
|
375
|
+
} else if (result == Z_BUF_ERROR || bb[0] === 0) {
|
|
376
|
+
z.msg = "incomplete dynamic bit lengths tree";
|
|
377
|
+
result = Z_DATA_ERROR;
|
|
378
|
+
}
|
|
379
|
+
return result;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
that.inflate_trees_dynamic = function (nl, // number of literal/length codes
|
|
383
|
+
nd, // number of distance codes
|
|
384
|
+
c, // that many (total) code lengths
|
|
385
|
+
bl, // literal desired/actual bit depth
|
|
386
|
+
bd, // distance desired/actual bit depth
|
|
387
|
+
tl, // literal/length tree result
|
|
388
|
+
td, // distance tree result
|
|
389
|
+
hp, // space for trees
|
|
390
|
+
z // for messages
|
|
391
|
+
) {
|
|
392
|
+
let result;
|
|
393
|
+
|
|
394
|
+
// build literal/length tree
|
|
395
|
+
initWorkArea(288);
|
|
396
|
+
hn[0] = 0;
|
|
397
|
+
result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
|
|
398
|
+
if (result != Z_OK || bl[0] === 0) {
|
|
399
|
+
if (result == Z_DATA_ERROR) {
|
|
400
|
+
z.msg = "oversubscribed literal/length tree";
|
|
401
|
+
} else if (result != Z_MEM_ERROR) {
|
|
402
|
+
z.msg = "incomplete literal/length tree";
|
|
403
|
+
result = Z_DATA_ERROR;
|
|
404
|
+
}
|
|
405
|
+
return result;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// build distance tree
|
|
409
|
+
initWorkArea(288);
|
|
410
|
+
result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
|
|
411
|
+
|
|
412
|
+
if (result != Z_OK || (bd[0] === 0 && nl > 257)) {
|
|
413
|
+
if (result == Z_DATA_ERROR) {
|
|
414
|
+
z.msg = "oversubscribed distance tree";
|
|
415
|
+
} else if (result == Z_BUF_ERROR) {
|
|
416
|
+
z.msg = "incomplete distance tree";
|
|
417
|
+
result = Z_DATA_ERROR;
|
|
418
|
+
} else if (result != Z_MEM_ERROR) {
|
|
419
|
+
z.msg = "empty distance tree with lengths";
|
|
420
|
+
result = Z_DATA_ERROR;
|
|
421
|
+
}
|
|
422
|
+
return result;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return Z_OK;
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
InfTree.inflate_trees_fixed = function (bl, // literal desired/actual bit depth
|
|
431
|
+
bd, // distance desired/actual bit depth
|
|
432
|
+
tl,// literal/length tree result
|
|
433
|
+
td// distance tree result
|
|
434
|
+
) {
|
|
435
|
+
bl[0] = fixed_bl;
|
|
436
|
+
bd[0] = fixed_bd;
|
|
437
|
+
tl[0] = fixed_tl;
|
|
438
|
+
td[0] = fixed_td;
|
|
439
|
+
return Z_OK;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// InfCodes
|
|
443
|
+
|
|
444
|
+
// waiting for "i:"=input,
|
|
445
|
+
// "o:"=output,
|
|
446
|
+
// "x:"=nothing
|
|
447
|
+
const START = 0; // x: set up for LEN
|
|
448
|
+
const LEN = 1; // i: get length/literal/eob next
|
|
449
|
+
const LENEXT = 2; // i: getting length extra (have base)
|
|
450
|
+
const DIST = 3; // i: get distance next
|
|
451
|
+
const DISTEXT = 4;// i: getting distance extra
|
|
452
|
+
const COPY = 5; // o: copying bytes in win, waiting
|
|
453
|
+
// for space
|
|
454
|
+
const LIT = 6; // o: got literal, waiting for output
|
|
455
|
+
// space
|
|
456
|
+
const WASH = 7; // o: got eob, possibly still output
|
|
457
|
+
// waiting
|
|
458
|
+
const END = 8; // x: got eob and all data flushed
|
|
459
|
+
const BADCODE = 9;// x: got error
|
|
460
|
+
|
|
461
|
+
function InfCodes() {
|
|
462
|
+
const that = this;
|
|
463
|
+
|
|
464
|
+
let mode; // current inflate_codes mode
|
|
465
|
+
|
|
466
|
+
// mode dependent information
|
|
467
|
+
let len = 0;
|
|
468
|
+
|
|
469
|
+
let tree; // pointer into tree
|
|
470
|
+
let tree_index = 0;
|
|
471
|
+
let need = 0; // bits needed
|
|
472
|
+
|
|
473
|
+
let lit = 0;
|
|
474
|
+
|
|
475
|
+
// if EXT or COPY, where and how much
|
|
476
|
+
let get = 0; // bits to get for extra
|
|
477
|
+
let dist = 0; // distance back to copy from
|
|
478
|
+
|
|
479
|
+
let lbits = 0; // ltree bits decoded per branch
|
|
480
|
+
let dbits = 0; // dtree bits decoder per branch
|
|
481
|
+
let ltree; // literal/length/eob tree
|
|
482
|
+
let ltree_index = 0; // literal/length/eob tree
|
|
483
|
+
let dtree; // distance tree
|
|
484
|
+
let dtree_index = 0; // distance tree
|
|
485
|
+
|
|
486
|
+
// Called with number of bytes left to write in win at least 258
|
|
487
|
+
// (the maximum string length) and number of input bytes available
|
|
488
|
+
// at least ten. The ten bytes are six bytes for the longest length/
|
|
489
|
+
// distance pair plus four bytes for overloading the bit buffer.
|
|
490
|
+
|
|
491
|
+
function inflate_fast(bl, bd, tl, tl_index, td, td_index, s, z) {
|
|
492
|
+
let t; // temporary pointer
|
|
493
|
+
let tp; // temporary pointer
|
|
494
|
+
let tp_index; // temporary pointer
|
|
495
|
+
let e; // extra bits or operation
|
|
496
|
+
let b; // bit buffer
|
|
497
|
+
let k; // bits in bit buffer
|
|
498
|
+
let p; // input data pointer
|
|
499
|
+
let n; // bytes available there
|
|
500
|
+
let q; // output win write pointer
|
|
501
|
+
let m; // bytes to end of win or read pointer
|
|
502
|
+
let ml; // mask for literal/length tree
|
|
503
|
+
let md; // mask for distance tree
|
|
504
|
+
let c; // bytes to copy
|
|
505
|
+
let d; // distance back to copy from
|
|
506
|
+
let r; // copy source pointer
|
|
507
|
+
|
|
508
|
+
let tp_index_t_3; // (tp_index+t)*3
|
|
509
|
+
|
|
510
|
+
// load input, output, bit values
|
|
511
|
+
p = z.next_in_index;
|
|
512
|
+
n = z.avail_in;
|
|
513
|
+
b = s.bitb;
|
|
514
|
+
k = s.bitk;
|
|
515
|
+
q = s.write;
|
|
516
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
517
|
+
|
|
518
|
+
// initialize masks
|
|
519
|
+
ml = inflate_mask[bl];
|
|
520
|
+
md = inflate_mask[bd];
|
|
521
|
+
|
|
522
|
+
// do until not enough input or output space for fast loop
|
|
523
|
+
do { // assume called with m >= 258 && n >= 10
|
|
524
|
+
// get literal/length code
|
|
525
|
+
while (k < (20)) { // max bits for literal/length code
|
|
526
|
+
n--;
|
|
527
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
528
|
+
k += 8;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
t = b & ml;
|
|
532
|
+
tp = tl;
|
|
533
|
+
tp_index = tl_index;
|
|
534
|
+
tp_index_t_3 = (tp_index + t) * 3;
|
|
535
|
+
if ((e = tp[tp_index_t_3]) === 0) {
|
|
536
|
+
b >>= (tp[tp_index_t_3 + 1]);
|
|
537
|
+
k -= (tp[tp_index_t_3 + 1]);
|
|
538
|
+
|
|
539
|
+
s.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];
|
|
540
|
+
m--;
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
do {
|
|
544
|
+
|
|
545
|
+
b >>= (tp[tp_index_t_3 + 1]);
|
|
546
|
+
k -= (tp[tp_index_t_3 + 1]);
|
|
547
|
+
|
|
548
|
+
if ((e & 16) !== 0) {
|
|
549
|
+
e &= 15;
|
|
550
|
+
c = tp[tp_index_t_3 + 2] + (/* (int) */b & inflate_mask[e]);
|
|
551
|
+
|
|
552
|
+
b >>= e;
|
|
553
|
+
k -= e;
|
|
554
|
+
|
|
555
|
+
// decode distance base of block to copy
|
|
556
|
+
while (k < (15)) { // max bits for distance code
|
|
557
|
+
n--;
|
|
558
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
559
|
+
k += 8;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
t = b & md;
|
|
563
|
+
tp = td;
|
|
564
|
+
tp_index = td_index;
|
|
565
|
+
tp_index_t_3 = (tp_index + t) * 3;
|
|
566
|
+
e = tp[tp_index_t_3];
|
|
567
|
+
|
|
568
|
+
do {
|
|
569
|
+
|
|
570
|
+
b >>= (tp[tp_index_t_3 + 1]);
|
|
571
|
+
k -= (tp[tp_index_t_3 + 1]);
|
|
572
|
+
|
|
573
|
+
if ((e & 16) !== 0) {
|
|
574
|
+
// get extra bits to add to distance base
|
|
575
|
+
e &= 15;
|
|
576
|
+
while (k < (e)) { // get extra bits (up to 13)
|
|
577
|
+
n--;
|
|
578
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
579
|
+
k += 8;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
d = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]);
|
|
583
|
+
|
|
584
|
+
b >>= (e);
|
|
585
|
+
k -= (e);
|
|
586
|
+
|
|
587
|
+
// do the copy
|
|
588
|
+
m -= c;
|
|
589
|
+
if (q >= d) { // offset before dest
|
|
590
|
+
// just copy
|
|
591
|
+
r = q - d;
|
|
592
|
+
if (q - r > 0 && 2 > (q - r)) {
|
|
593
|
+
s.win[q++] = s.win[r++]; // minimum
|
|
594
|
+
// count is
|
|
595
|
+
// three,
|
|
596
|
+
s.win[q++] = s.win[r++]; // so unroll
|
|
597
|
+
// loop a
|
|
598
|
+
// little
|
|
599
|
+
c -= 2;
|
|
600
|
+
} else {
|
|
601
|
+
s.win.set(s.win.subarray(r, r + 2), q);
|
|
602
|
+
q += 2;
|
|
603
|
+
r += 2;
|
|
604
|
+
c -= 2;
|
|
605
|
+
}
|
|
606
|
+
} else { // else offset after destination
|
|
607
|
+
r = q - d;
|
|
608
|
+
do {
|
|
609
|
+
r += s.end; // force pointer in win
|
|
610
|
+
} while (r < 0); // covers invalid distances
|
|
611
|
+
e = s.end - r;
|
|
612
|
+
if (c > e) { // if source crosses,
|
|
613
|
+
c -= e; // wrapped copy
|
|
614
|
+
if (q - r > 0 && e > (q - r)) {
|
|
615
|
+
do {
|
|
616
|
+
s.win[q++] = s.win[r++];
|
|
617
|
+
} while (--e !== 0);
|
|
618
|
+
} else {
|
|
619
|
+
s.win.set(s.win.subarray(r, r + e), q);
|
|
620
|
+
q += e;
|
|
621
|
+
r += e;
|
|
622
|
+
e = 0;
|
|
623
|
+
}
|
|
624
|
+
r = 0; // copy rest from start of win
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// copy all or what's left
|
|
630
|
+
if (q - r > 0 && c > (q - r)) {
|
|
631
|
+
do {
|
|
632
|
+
s.win[q++] = s.win[r++];
|
|
633
|
+
} while (--c !== 0);
|
|
634
|
+
} else {
|
|
635
|
+
s.win.set(s.win.subarray(r, r + c), q);
|
|
636
|
+
q += c;
|
|
637
|
+
r += c;
|
|
638
|
+
c = 0;
|
|
639
|
+
}
|
|
640
|
+
break;
|
|
641
|
+
} else if ((e & 64) === 0) {
|
|
642
|
+
t += tp[tp_index_t_3 + 2];
|
|
643
|
+
t += (b & inflate_mask[e]);
|
|
644
|
+
tp_index_t_3 = (tp_index + t) * 3;
|
|
645
|
+
e = tp[tp_index_t_3];
|
|
646
|
+
} else {
|
|
647
|
+
z.msg = "invalid distance code";
|
|
648
|
+
|
|
649
|
+
c = z.avail_in - n;
|
|
650
|
+
c = (k >> 3) < c ? k >> 3 : c;
|
|
651
|
+
n += c;
|
|
652
|
+
p -= c;
|
|
653
|
+
k -= c << 3;
|
|
654
|
+
|
|
655
|
+
s.bitb = b;
|
|
656
|
+
s.bitk = k;
|
|
657
|
+
z.avail_in = n;
|
|
658
|
+
z.total_in += p - z.next_in_index;
|
|
659
|
+
z.next_in_index = p;
|
|
660
|
+
s.write = q;
|
|
661
|
+
|
|
662
|
+
return Z_DATA_ERROR;
|
|
663
|
+
}
|
|
664
|
+
// eslint-disable-next-line no-constant-condition
|
|
665
|
+
} while (true);
|
|
666
|
+
break;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
if ((e & 64) === 0) {
|
|
670
|
+
t += tp[tp_index_t_3 + 2];
|
|
671
|
+
t += (b & inflate_mask[e]);
|
|
672
|
+
tp_index_t_3 = (tp_index + t) * 3;
|
|
673
|
+
if ((e = tp[tp_index_t_3]) === 0) {
|
|
674
|
+
|
|
675
|
+
b >>= (tp[tp_index_t_3 + 1]);
|
|
676
|
+
k -= (tp[tp_index_t_3 + 1]);
|
|
677
|
+
|
|
678
|
+
s.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];
|
|
679
|
+
m--;
|
|
680
|
+
break;
|
|
681
|
+
}
|
|
682
|
+
} else if ((e & 32) !== 0) {
|
|
683
|
+
|
|
684
|
+
c = z.avail_in - n;
|
|
685
|
+
c = (k >> 3) < c ? k >> 3 : c;
|
|
686
|
+
n += c;
|
|
687
|
+
p -= c;
|
|
688
|
+
k -= c << 3;
|
|
689
|
+
|
|
690
|
+
s.bitb = b;
|
|
691
|
+
s.bitk = k;
|
|
692
|
+
z.avail_in = n;
|
|
693
|
+
z.total_in += p - z.next_in_index;
|
|
694
|
+
z.next_in_index = p;
|
|
695
|
+
s.write = q;
|
|
696
|
+
|
|
697
|
+
return Z_STREAM_END;
|
|
698
|
+
} else {
|
|
699
|
+
z.msg = "invalid literal/length code";
|
|
700
|
+
|
|
701
|
+
c = z.avail_in - n;
|
|
702
|
+
c = (k >> 3) < c ? k >> 3 : c;
|
|
703
|
+
n += c;
|
|
704
|
+
p -= c;
|
|
705
|
+
k -= c << 3;
|
|
706
|
+
|
|
707
|
+
s.bitb = b;
|
|
708
|
+
s.bitk = k;
|
|
709
|
+
z.avail_in = n;
|
|
710
|
+
z.total_in += p - z.next_in_index;
|
|
711
|
+
z.next_in_index = p;
|
|
712
|
+
s.write = q;
|
|
713
|
+
|
|
714
|
+
return Z_DATA_ERROR;
|
|
715
|
+
}
|
|
716
|
+
// eslint-disable-next-line no-constant-condition
|
|
717
|
+
} while (true);
|
|
718
|
+
} while (m >= 258 && n >= 10);
|
|
719
|
+
|
|
720
|
+
// not enough input or output--restore pointers and return
|
|
721
|
+
c = z.avail_in - n;
|
|
722
|
+
c = (k >> 3) < c ? k >> 3 : c;
|
|
723
|
+
n += c;
|
|
724
|
+
p -= c;
|
|
725
|
+
k -= c << 3;
|
|
726
|
+
|
|
727
|
+
s.bitb = b;
|
|
728
|
+
s.bitk = k;
|
|
729
|
+
z.avail_in = n;
|
|
730
|
+
z.total_in += p - z.next_in_index;
|
|
731
|
+
z.next_in_index = p;
|
|
732
|
+
s.write = q;
|
|
733
|
+
|
|
734
|
+
return Z_OK;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
that.init = function (bl, bd, tl, tl_index, td, td_index) {
|
|
738
|
+
mode = START;
|
|
739
|
+
lbits = /* (byte) */bl;
|
|
740
|
+
dbits = /* (byte) */bd;
|
|
741
|
+
ltree = tl;
|
|
742
|
+
ltree_index = tl_index;
|
|
743
|
+
dtree = td;
|
|
744
|
+
dtree_index = td_index;
|
|
745
|
+
tree = null;
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
that.proc = function (s, z, r) {
|
|
749
|
+
let j; // temporary storage
|
|
750
|
+
let tindex; // temporary pointer
|
|
751
|
+
let e; // extra bits or operation
|
|
752
|
+
let b = 0; // bit buffer
|
|
753
|
+
let k = 0; // bits in bit buffer
|
|
754
|
+
let p = 0; // input data pointer
|
|
755
|
+
let n; // bytes available there
|
|
756
|
+
let q; // output win write pointer
|
|
757
|
+
let m; // bytes to end of win or read pointer
|
|
758
|
+
let f; // pointer to copy strings from
|
|
759
|
+
|
|
760
|
+
// copy input/output information to locals (UPDATE macro restores)
|
|
761
|
+
p = z.next_in_index;
|
|
762
|
+
n = z.avail_in;
|
|
763
|
+
b = s.bitb;
|
|
764
|
+
k = s.bitk;
|
|
765
|
+
q = s.write;
|
|
766
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
767
|
+
|
|
768
|
+
// process input and output based on current state
|
|
769
|
+
// eslint-disable-next-line no-constant-condition
|
|
770
|
+
while (true) {
|
|
771
|
+
switch (mode) {
|
|
772
|
+
// waiting for "i:"=input, "o:"=output, "x:"=nothing
|
|
773
|
+
case START: // x: set up for LEN
|
|
774
|
+
if (m >= 258 && n >= 10) {
|
|
775
|
+
|
|
776
|
+
s.bitb = b;
|
|
777
|
+
s.bitk = k;
|
|
778
|
+
z.avail_in = n;
|
|
779
|
+
z.total_in += p - z.next_in_index;
|
|
780
|
+
z.next_in_index = p;
|
|
781
|
+
s.write = q;
|
|
782
|
+
r = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z);
|
|
783
|
+
|
|
784
|
+
p = z.next_in_index;
|
|
785
|
+
n = z.avail_in;
|
|
786
|
+
b = s.bitb;
|
|
787
|
+
k = s.bitk;
|
|
788
|
+
q = s.write;
|
|
789
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
790
|
+
|
|
791
|
+
if (r != Z_OK) {
|
|
792
|
+
mode = r == Z_STREAM_END ? WASH : BADCODE;
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
need = lbits;
|
|
797
|
+
tree = ltree;
|
|
798
|
+
tree_index = ltree_index;
|
|
799
|
+
|
|
800
|
+
mode = LEN;
|
|
801
|
+
/* falls through */
|
|
802
|
+
case LEN: // i: get length/literal/eob next
|
|
803
|
+
j = need;
|
|
804
|
+
|
|
805
|
+
while (k < (j)) {
|
|
806
|
+
if (n !== 0)
|
|
807
|
+
r = Z_OK;
|
|
808
|
+
else {
|
|
809
|
+
|
|
810
|
+
s.bitb = b;
|
|
811
|
+
s.bitk = k;
|
|
812
|
+
z.avail_in = n;
|
|
813
|
+
z.total_in += p - z.next_in_index;
|
|
814
|
+
z.next_in_index = p;
|
|
815
|
+
s.write = q;
|
|
816
|
+
return s.inflate_flush(z, r);
|
|
817
|
+
}
|
|
818
|
+
n--;
|
|
819
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
820
|
+
k += 8;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
tindex = (tree_index + (b & inflate_mask[j])) * 3;
|
|
824
|
+
|
|
825
|
+
b >>>= (tree[tindex + 1]);
|
|
826
|
+
k -= (tree[tindex + 1]);
|
|
827
|
+
|
|
828
|
+
e = tree[tindex];
|
|
829
|
+
|
|
830
|
+
if (e === 0) { // literal
|
|
831
|
+
lit = tree[tindex + 2];
|
|
832
|
+
mode = LIT;
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
if ((e & 16) !== 0) { // length
|
|
836
|
+
get = e & 15;
|
|
837
|
+
len = tree[tindex + 2];
|
|
838
|
+
mode = LENEXT;
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
if ((e & 64) === 0) { // next table
|
|
842
|
+
need = e;
|
|
843
|
+
tree_index = tindex / 3 + tree[tindex + 2];
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
if ((e & 32) !== 0) { // end of block
|
|
847
|
+
mode = WASH;
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
mode = BADCODE; // invalid code
|
|
851
|
+
z.msg = "invalid literal/length code";
|
|
852
|
+
r = Z_DATA_ERROR;
|
|
853
|
+
|
|
854
|
+
s.bitb = b;
|
|
855
|
+
s.bitk = k;
|
|
856
|
+
z.avail_in = n;
|
|
857
|
+
z.total_in += p - z.next_in_index;
|
|
858
|
+
z.next_in_index = p;
|
|
859
|
+
s.write = q;
|
|
860
|
+
return s.inflate_flush(z, r);
|
|
861
|
+
|
|
862
|
+
case LENEXT: // i: getting length extra (have base)
|
|
863
|
+
j = get;
|
|
864
|
+
|
|
865
|
+
while (k < (j)) {
|
|
866
|
+
if (n !== 0)
|
|
867
|
+
r = Z_OK;
|
|
868
|
+
else {
|
|
869
|
+
|
|
870
|
+
s.bitb = b;
|
|
871
|
+
s.bitk = k;
|
|
872
|
+
z.avail_in = n;
|
|
873
|
+
z.total_in += p - z.next_in_index;
|
|
874
|
+
z.next_in_index = p;
|
|
875
|
+
s.write = q;
|
|
876
|
+
return s.inflate_flush(z, r);
|
|
877
|
+
}
|
|
878
|
+
n--;
|
|
879
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
880
|
+
k += 8;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
len += (b & inflate_mask[j]);
|
|
884
|
+
|
|
885
|
+
b >>= j;
|
|
886
|
+
k -= j;
|
|
887
|
+
|
|
888
|
+
need = dbits;
|
|
889
|
+
tree = dtree;
|
|
890
|
+
tree_index = dtree_index;
|
|
891
|
+
mode = DIST;
|
|
892
|
+
/* falls through */
|
|
893
|
+
case DIST: // i: get distance next
|
|
894
|
+
j = need;
|
|
895
|
+
|
|
896
|
+
while (k < (j)) {
|
|
897
|
+
if (n !== 0)
|
|
898
|
+
r = Z_OK;
|
|
899
|
+
else {
|
|
900
|
+
|
|
901
|
+
s.bitb = b;
|
|
902
|
+
s.bitk = k;
|
|
903
|
+
z.avail_in = n;
|
|
904
|
+
z.total_in += p - z.next_in_index;
|
|
905
|
+
z.next_in_index = p;
|
|
906
|
+
s.write = q;
|
|
907
|
+
return s.inflate_flush(z, r);
|
|
908
|
+
}
|
|
909
|
+
n--;
|
|
910
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
911
|
+
k += 8;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
tindex = (tree_index + (b & inflate_mask[j])) * 3;
|
|
915
|
+
|
|
916
|
+
b >>= tree[tindex + 1];
|
|
917
|
+
k -= tree[tindex + 1];
|
|
918
|
+
|
|
919
|
+
e = (tree[tindex]);
|
|
920
|
+
if ((e & 16) !== 0) { // distance
|
|
921
|
+
get = e & 15;
|
|
922
|
+
dist = tree[tindex + 2];
|
|
923
|
+
mode = DISTEXT;
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
if ((e & 64) === 0) { // next table
|
|
927
|
+
need = e;
|
|
928
|
+
tree_index = tindex / 3 + tree[tindex + 2];
|
|
929
|
+
break;
|
|
930
|
+
}
|
|
931
|
+
mode = BADCODE; // invalid code
|
|
932
|
+
z.msg = "invalid distance code";
|
|
933
|
+
r = Z_DATA_ERROR;
|
|
934
|
+
|
|
935
|
+
s.bitb = b;
|
|
936
|
+
s.bitk = k;
|
|
937
|
+
z.avail_in = n;
|
|
938
|
+
z.total_in += p - z.next_in_index;
|
|
939
|
+
z.next_in_index = p;
|
|
940
|
+
s.write = q;
|
|
941
|
+
return s.inflate_flush(z, r);
|
|
942
|
+
|
|
943
|
+
case DISTEXT: // i: getting distance extra
|
|
944
|
+
j = get;
|
|
945
|
+
|
|
946
|
+
while (k < (j)) {
|
|
947
|
+
if (n !== 0)
|
|
948
|
+
r = Z_OK;
|
|
949
|
+
else {
|
|
950
|
+
|
|
951
|
+
s.bitb = b;
|
|
952
|
+
s.bitk = k;
|
|
953
|
+
z.avail_in = n;
|
|
954
|
+
z.total_in += p - z.next_in_index;
|
|
955
|
+
z.next_in_index = p;
|
|
956
|
+
s.write = q;
|
|
957
|
+
return s.inflate_flush(z, r);
|
|
958
|
+
}
|
|
959
|
+
n--;
|
|
960
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
961
|
+
k += 8;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
dist += (b & inflate_mask[j]);
|
|
965
|
+
|
|
966
|
+
b >>= j;
|
|
967
|
+
k -= j;
|
|
968
|
+
|
|
969
|
+
mode = COPY;
|
|
970
|
+
/* falls through */
|
|
971
|
+
case COPY: // o: copying bytes in win, waiting for space
|
|
972
|
+
f = q - dist;
|
|
973
|
+
while (f < 0) { // modulo win size-"while" instead
|
|
974
|
+
f += s.end; // of "if" handles invalid distances
|
|
975
|
+
}
|
|
976
|
+
while (len !== 0) {
|
|
977
|
+
|
|
978
|
+
if (m === 0) {
|
|
979
|
+
if (q == s.end && s.read !== 0) {
|
|
980
|
+
q = 0;
|
|
981
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
982
|
+
}
|
|
983
|
+
if (m === 0) {
|
|
984
|
+
s.write = q;
|
|
985
|
+
r = s.inflate_flush(z, r);
|
|
986
|
+
q = s.write;
|
|
987
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
988
|
+
|
|
989
|
+
if (q == s.end && s.read !== 0) {
|
|
990
|
+
q = 0;
|
|
991
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
if (m === 0) {
|
|
995
|
+
s.bitb = b;
|
|
996
|
+
s.bitk = k;
|
|
997
|
+
z.avail_in = n;
|
|
998
|
+
z.total_in += p - z.next_in_index;
|
|
999
|
+
z.next_in_index = p;
|
|
1000
|
+
s.write = q;
|
|
1001
|
+
return s.inflate_flush(z, r);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
s.win[q++] = s.win[f++];
|
|
1007
|
+
m--;
|
|
1008
|
+
|
|
1009
|
+
if (f == s.end)
|
|
1010
|
+
f = 0;
|
|
1011
|
+
len--;
|
|
1012
|
+
}
|
|
1013
|
+
mode = START;
|
|
1014
|
+
break;
|
|
1015
|
+
case LIT: // o: got literal, waiting for output space
|
|
1016
|
+
if (m === 0) {
|
|
1017
|
+
if (q == s.end && s.read !== 0) {
|
|
1018
|
+
q = 0;
|
|
1019
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
1020
|
+
}
|
|
1021
|
+
if (m === 0) {
|
|
1022
|
+
s.write = q;
|
|
1023
|
+
r = s.inflate_flush(z, r);
|
|
1024
|
+
q = s.write;
|
|
1025
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
1026
|
+
|
|
1027
|
+
if (q == s.end && s.read !== 0) {
|
|
1028
|
+
q = 0;
|
|
1029
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
1030
|
+
}
|
|
1031
|
+
if (m === 0) {
|
|
1032
|
+
s.bitb = b;
|
|
1033
|
+
s.bitk = k;
|
|
1034
|
+
z.avail_in = n;
|
|
1035
|
+
z.total_in += p - z.next_in_index;
|
|
1036
|
+
z.next_in_index = p;
|
|
1037
|
+
s.write = q;
|
|
1038
|
+
return s.inflate_flush(z, r);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
r = Z_OK;
|
|
1043
|
+
|
|
1044
|
+
s.win[q++] = /* (byte) */lit;
|
|
1045
|
+
m--;
|
|
1046
|
+
|
|
1047
|
+
mode = START;
|
|
1048
|
+
break;
|
|
1049
|
+
case WASH: // o: got eob, possibly more output
|
|
1050
|
+
if (k > 7) { // return unused byte, if any
|
|
1051
|
+
k -= 8;
|
|
1052
|
+
n++;
|
|
1053
|
+
p--; // can always return one
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
s.write = q;
|
|
1057
|
+
r = s.inflate_flush(z, r);
|
|
1058
|
+
q = s.write;
|
|
1059
|
+
m = q < s.read ? s.read - q - 1 : s.end - q;
|
|
1060
|
+
|
|
1061
|
+
if (s.read != s.write) {
|
|
1062
|
+
s.bitb = b;
|
|
1063
|
+
s.bitk = k;
|
|
1064
|
+
z.avail_in = n;
|
|
1065
|
+
z.total_in += p - z.next_in_index;
|
|
1066
|
+
z.next_in_index = p;
|
|
1067
|
+
s.write = q;
|
|
1068
|
+
return s.inflate_flush(z, r);
|
|
1069
|
+
}
|
|
1070
|
+
mode = END;
|
|
1071
|
+
/* falls through */
|
|
1072
|
+
case END:
|
|
1073
|
+
r = Z_STREAM_END;
|
|
1074
|
+
s.bitb = b;
|
|
1075
|
+
s.bitk = k;
|
|
1076
|
+
z.avail_in = n;
|
|
1077
|
+
z.total_in += p - z.next_in_index;
|
|
1078
|
+
z.next_in_index = p;
|
|
1079
|
+
s.write = q;
|
|
1080
|
+
return s.inflate_flush(z, r);
|
|
1081
|
+
|
|
1082
|
+
case BADCODE: // x: got error
|
|
1083
|
+
|
|
1084
|
+
r = Z_DATA_ERROR;
|
|
1085
|
+
|
|
1086
|
+
s.bitb = b;
|
|
1087
|
+
s.bitk = k;
|
|
1088
|
+
z.avail_in = n;
|
|
1089
|
+
z.total_in += p - z.next_in_index;
|
|
1090
|
+
z.next_in_index = p;
|
|
1091
|
+
s.write = q;
|
|
1092
|
+
return s.inflate_flush(z, r);
|
|
1093
|
+
|
|
1094
|
+
default:
|
|
1095
|
+
r = Z_STREAM_ERROR;
|
|
1096
|
+
|
|
1097
|
+
s.bitb = b;
|
|
1098
|
+
s.bitk = k;
|
|
1099
|
+
z.avail_in = n;
|
|
1100
|
+
z.total_in += p - z.next_in_index;
|
|
1101
|
+
z.next_in_index = p;
|
|
1102
|
+
s.write = q;
|
|
1103
|
+
return s.inflate_flush(z, r);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
that.free = function () {
|
|
1109
|
+
// ZFREE(z, c);
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// InfBlocks
|
|
1115
|
+
|
|
1116
|
+
// Table for deflate from PKZIP's appnote.txt.
|
|
1117
|
+
const border = [ // Order of the bit length code lengths
|
|
1118
|
+
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
|
|
1119
|
+
|
|
1120
|
+
const TYPE = 0; // get type bits (3, including end bit)
|
|
1121
|
+
const LENS = 1; // get lengths for stored
|
|
1122
|
+
const STORED = 2;// processing stored block
|
|
1123
|
+
const TABLE = 3; // get table lengths
|
|
1124
|
+
const BTREE = 4; // get bit lengths tree for a dynamic
|
|
1125
|
+
// block
|
|
1126
|
+
const DTREE = 5; // get length, distance trees for a
|
|
1127
|
+
// dynamic block
|
|
1128
|
+
const CODES = 6; // processing fixed or dynamic block
|
|
1129
|
+
const DRY = 7; // output remaining win bytes
|
|
1130
|
+
const DONELOCKS = 8; // finished last block, done
|
|
1131
|
+
const BADBLOCKS = 9; // ot a data error--stuck here
|
|
1132
|
+
|
|
1133
|
+
function InfBlocks(z, w) {
|
|
1134
|
+
const that = this;
|
|
1135
|
+
|
|
1136
|
+
let mode = TYPE; // current inflate_block mode
|
|
1137
|
+
|
|
1138
|
+
let left = 0; // if STORED, bytes left to copy
|
|
1139
|
+
|
|
1140
|
+
let table = 0; // table lengths (14 bits)
|
|
1141
|
+
let index = 0; // index into blens (or border)
|
|
1142
|
+
let blens; // bit lengths of codes
|
|
1143
|
+
const bb = [0]; // bit length tree depth
|
|
1144
|
+
const tb = [0]; // bit length decoding tree
|
|
1145
|
+
|
|
1146
|
+
const codes = new InfCodes(); // if CODES, current state
|
|
1147
|
+
|
|
1148
|
+
let last = 0; // true if this block is the last block
|
|
1149
|
+
|
|
1150
|
+
let hufts = new Int32Array(MANY * 3); // single malloc for tree space
|
|
1151
|
+
const check = 0; // check on output
|
|
1152
|
+
const inftree = new InfTree();
|
|
1153
|
+
|
|
1154
|
+
that.bitk = 0; // bits in bit buffer
|
|
1155
|
+
that.bitb = 0; // bit buffer
|
|
1156
|
+
that.win = new Uint8Array(w); // sliding win
|
|
1157
|
+
that.end = w; // one byte after sliding win
|
|
1158
|
+
that.read = 0; // win read pointer
|
|
1159
|
+
that.write = 0; // win write pointer
|
|
1160
|
+
|
|
1161
|
+
that.reset = function (z, c) {
|
|
1162
|
+
if (c)
|
|
1163
|
+
c[0] = check;
|
|
1164
|
+
// if (mode == BTREE || mode == DTREE) {
|
|
1165
|
+
// }
|
|
1166
|
+
if (mode == CODES) {
|
|
1167
|
+
codes.free(z);
|
|
1168
|
+
}
|
|
1169
|
+
mode = TYPE;
|
|
1170
|
+
that.bitk = 0;
|
|
1171
|
+
that.bitb = 0;
|
|
1172
|
+
that.read = that.write = 0;
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
that.reset(z, null);
|
|
1176
|
+
|
|
1177
|
+
// copy as much as possible from the sliding win to the output area
|
|
1178
|
+
that.inflate_flush = function (z, r) {
|
|
1179
|
+
let n;
|
|
1180
|
+
let p;
|
|
1181
|
+
let q;
|
|
1182
|
+
|
|
1183
|
+
// local copies of source and destination pointers
|
|
1184
|
+
p = z.next_out_index;
|
|
1185
|
+
q = that.read;
|
|
1186
|
+
|
|
1187
|
+
// compute number of bytes to copy as far as end of win
|
|
1188
|
+
n = /* (int) */((q <= that.write ? that.write : that.end) - q);
|
|
1189
|
+
if (n > z.avail_out)
|
|
1190
|
+
n = z.avail_out;
|
|
1191
|
+
if (n !== 0 && r == Z_BUF_ERROR)
|
|
1192
|
+
r = Z_OK;
|
|
1193
|
+
|
|
1194
|
+
// update counters
|
|
1195
|
+
z.avail_out -= n;
|
|
1196
|
+
z.total_out += n;
|
|
1197
|
+
|
|
1198
|
+
// copy as far as end of win
|
|
1199
|
+
z.next_out.set(that.win.subarray(q, q + n), p);
|
|
1200
|
+
p += n;
|
|
1201
|
+
q += n;
|
|
1202
|
+
|
|
1203
|
+
// see if more to copy at beginning of win
|
|
1204
|
+
if (q == that.end) {
|
|
1205
|
+
// wrap pointers
|
|
1206
|
+
q = 0;
|
|
1207
|
+
if (that.write == that.end)
|
|
1208
|
+
that.write = 0;
|
|
1209
|
+
|
|
1210
|
+
// compute bytes to copy
|
|
1211
|
+
n = that.write - q;
|
|
1212
|
+
if (n > z.avail_out)
|
|
1213
|
+
n = z.avail_out;
|
|
1214
|
+
if (n !== 0 && r == Z_BUF_ERROR)
|
|
1215
|
+
r = Z_OK;
|
|
1216
|
+
|
|
1217
|
+
// update counters
|
|
1218
|
+
z.avail_out -= n;
|
|
1219
|
+
z.total_out += n;
|
|
1220
|
+
|
|
1221
|
+
// copy
|
|
1222
|
+
z.next_out.set(that.win.subarray(q, q + n), p);
|
|
1223
|
+
p += n;
|
|
1224
|
+
q += n;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// update pointers
|
|
1228
|
+
z.next_out_index = p;
|
|
1229
|
+
that.read = q;
|
|
1230
|
+
|
|
1231
|
+
// done
|
|
1232
|
+
return r;
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
that.proc = function (z, r) {
|
|
1236
|
+
let t; // temporary storage
|
|
1237
|
+
let b; // bit buffer
|
|
1238
|
+
let k; // bits in bit buffer
|
|
1239
|
+
let p; // input data pointer
|
|
1240
|
+
let n; // bytes available there
|
|
1241
|
+
let q; // output win write pointer
|
|
1242
|
+
let m; // bytes to end of win or read pointer
|
|
1243
|
+
|
|
1244
|
+
let i;
|
|
1245
|
+
|
|
1246
|
+
// copy input/output information to locals (UPDATE macro restores)
|
|
1247
|
+
// {
|
|
1248
|
+
p = z.next_in_index;
|
|
1249
|
+
n = z.avail_in;
|
|
1250
|
+
b = that.bitb;
|
|
1251
|
+
k = that.bitk;
|
|
1252
|
+
// }
|
|
1253
|
+
// {
|
|
1254
|
+
q = that.write;
|
|
1255
|
+
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
|
|
1256
|
+
// }
|
|
1257
|
+
|
|
1258
|
+
// process input based on current state
|
|
1259
|
+
// DEBUG dtree
|
|
1260
|
+
// eslint-disable-next-line no-constant-condition
|
|
1261
|
+
while (true) {
|
|
1262
|
+
let bl, bd, tl, td, bl_, bd_, tl_, td_;
|
|
1263
|
+
switch (mode) {
|
|
1264
|
+
case TYPE:
|
|
1265
|
+
|
|
1266
|
+
while (k < (3)) {
|
|
1267
|
+
if (n !== 0) {
|
|
1268
|
+
r = Z_OK;
|
|
1269
|
+
} else {
|
|
1270
|
+
that.bitb = b;
|
|
1271
|
+
that.bitk = k;
|
|
1272
|
+
z.avail_in = n;
|
|
1273
|
+
z.total_in += p - z.next_in_index;
|
|
1274
|
+
z.next_in_index = p;
|
|
1275
|
+
that.write = q;
|
|
1276
|
+
return that.inflate_flush(z, r);
|
|
1277
|
+
}
|
|
1278
|
+
n--;
|
|
1279
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
1280
|
+
k += 8;
|
|
1281
|
+
}
|
|
1282
|
+
t = /* (int) */(b & 7);
|
|
1283
|
+
last = t & 1;
|
|
1284
|
+
|
|
1285
|
+
switch (t >>> 1) {
|
|
1286
|
+
case 0: // stored
|
|
1287
|
+
// {
|
|
1288
|
+
b >>>= (3);
|
|
1289
|
+
k -= (3);
|
|
1290
|
+
// }
|
|
1291
|
+
t = k & 7; // go to byte boundary
|
|
1292
|
+
|
|
1293
|
+
// {
|
|
1294
|
+
b >>>= (t);
|
|
1295
|
+
k -= (t);
|
|
1296
|
+
// }
|
|
1297
|
+
mode = LENS; // get length of stored block
|
|
1298
|
+
break;
|
|
1299
|
+
case 1: // fixed
|
|
1300
|
+
// {
|
|
1301
|
+
bl = []; // new Array(1);
|
|
1302
|
+
bd = []; // new Array(1);
|
|
1303
|
+
tl = [[]]; // new Array(1);
|
|
1304
|
+
td = [[]]; // new Array(1);
|
|
1305
|
+
|
|
1306
|
+
InfTree.inflate_trees_fixed(bl, bd, tl, td);
|
|
1307
|
+
codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
|
|
1308
|
+
// }
|
|
1309
|
+
|
|
1310
|
+
// {
|
|
1311
|
+
b >>>= (3);
|
|
1312
|
+
k -= (3);
|
|
1313
|
+
// }
|
|
1314
|
+
|
|
1315
|
+
mode = CODES;
|
|
1316
|
+
break;
|
|
1317
|
+
case 2: // dynamic
|
|
1318
|
+
|
|
1319
|
+
// {
|
|
1320
|
+
b >>>= (3);
|
|
1321
|
+
k -= (3);
|
|
1322
|
+
// }
|
|
1323
|
+
|
|
1324
|
+
mode = TABLE;
|
|
1325
|
+
break;
|
|
1326
|
+
case 3: // illegal
|
|
1327
|
+
|
|
1328
|
+
// {
|
|
1329
|
+
b >>>= (3);
|
|
1330
|
+
k -= (3);
|
|
1331
|
+
// }
|
|
1332
|
+
mode = BADBLOCKS;
|
|
1333
|
+
z.msg = "invalid block type";
|
|
1334
|
+
r = Z_DATA_ERROR;
|
|
1335
|
+
|
|
1336
|
+
that.bitb = b;
|
|
1337
|
+
that.bitk = k;
|
|
1338
|
+
z.avail_in = n;
|
|
1339
|
+
z.total_in += p - z.next_in_index;
|
|
1340
|
+
z.next_in_index = p;
|
|
1341
|
+
that.write = q;
|
|
1342
|
+
return that.inflate_flush(z, r);
|
|
1343
|
+
}
|
|
1344
|
+
break;
|
|
1345
|
+
case LENS:
|
|
1346
|
+
|
|
1347
|
+
while (k < (32)) {
|
|
1348
|
+
if (n !== 0) {
|
|
1349
|
+
r = Z_OK;
|
|
1350
|
+
} else {
|
|
1351
|
+
that.bitb = b;
|
|
1352
|
+
that.bitk = k;
|
|
1353
|
+
z.avail_in = n;
|
|
1354
|
+
z.total_in += p - z.next_in_index;
|
|
1355
|
+
z.next_in_index = p;
|
|
1356
|
+
that.write = q;
|
|
1357
|
+
return that.inflate_flush(z, r);
|
|
1358
|
+
}
|
|
1359
|
+
n--;
|
|
1360
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
1361
|
+
k += 8;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) {
|
|
1365
|
+
mode = BADBLOCKS;
|
|
1366
|
+
z.msg = "invalid stored block lengths";
|
|
1367
|
+
r = Z_DATA_ERROR;
|
|
1368
|
+
|
|
1369
|
+
that.bitb = b;
|
|
1370
|
+
that.bitk = k;
|
|
1371
|
+
z.avail_in = n;
|
|
1372
|
+
z.total_in += p - z.next_in_index;
|
|
1373
|
+
z.next_in_index = p;
|
|
1374
|
+
that.write = q;
|
|
1375
|
+
return that.inflate_flush(z, r);
|
|
1376
|
+
}
|
|
1377
|
+
left = (b & 0xffff);
|
|
1378
|
+
b = k = 0; // dump bits
|
|
1379
|
+
mode = left !== 0 ? STORED : (last !== 0 ? DRY : TYPE);
|
|
1380
|
+
break;
|
|
1381
|
+
case STORED:
|
|
1382
|
+
if (n === 0) {
|
|
1383
|
+
that.bitb = b;
|
|
1384
|
+
that.bitk = k;
|
|
1385
|
+
z.avail_in = n;
|
|
1386
|
+
z.total_in += p - z.next_in_index;
|
|
1387
|
+
z.next_in_index = p;
|
|
1388
|
+
that.write = q;
|
|
1389
|
+
return that.inflate_flush(z, r);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
if (m === 0) {
|
|
1393
|
+
if (q == that.end && that.read !== 0) {
|
|
1394
|
+
q = 0;
|
|
1395
|
+
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
|
|
1396
|
+
}
|
|
1397
|
+
if (m === 0) {
|
|
1398
|
+
that.write = q;
|
|
1399
|
+
r = that.inflate_flush(z, r);
|
|
1400
|
+
q = that.write;
|
|
1401
|
+
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
|
|
1402
|
+
if (q == that.end && that.read !== 0) {
|
|
1403
|
+
q = 0;
|
|
1404
|
+
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
|
|
1405
|
+
}
|
|
1406
|
+
if (m === 0) {
|
|
1407
|
+
that.bitb = b;
|
|
1408
|
+
that.bitk = k;
|
|
1409
|
+
z.avail_in = n;
|
|
1410
|
+
z.total_in += p - z.next_in_index;
|
|
1411
|
+
z.next_in_index = p;
|
|
1412
|
+
that.write = q;
|
|
1413
|
+
return that.inflate_flush(z, r);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
r = Z_OK;
|
|
1418
|
+
|
|
1419
|
+
t = left;
|
|
1420
|
+
if (t > n)
|
|
1421
|
+
t = n;
|
|
1422
|
+
if (t > m)
|
|
1423
|
+
t = m;
|
|
1424
|
+
that.win.set(z.read_buf(p, t), q);
|
|
1425
|
+
p += t;
|
|
1426
|
+
n -= t;
|
|
1427
|
+
q += t;
|
|
1428
|
+
m -= t;
|
|
1429
|
+
if ((left -= t) !== 0)
|
|
1430
|
+
break;
|
|
1431
|
+
mode = last !== 0 ? DRY : TYPE;
|
|
1432
|
+
break;
|
|
1433
|
+
case TABLE:
|
|
1434
|
+
|
|
1435
|
+
while (k < (14)) {
|
|
1436
|
+
if (n !== 0) {
|
|
1437
|
+
r = Z_OK;
|
|
1438
|
+
} else {
|
|
1439
|
+
that.bitb = b;
|
|
1440
|
+
that.bitk = k;
|
|
1441
|
+
z.avail_in = n;
|
|
1442
|
+
z.total_in += p - z.next_in_index;
|
|
1443
|
+
z.next_in_index = p;
|
|
1444
|
+
that.write = q;
|
|
1445
|
+
return that.inflate_flush(z, r);
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
n--;
|
|
1449
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
1450
|
+
k += 8;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
table = t = (b & 0x3fff);
|
|
1454
|
+
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
|
|
1455
|
+
mode = BADBLOCKS;
|
|
1456
|
+
z.msg = "too many length or distance symbols";
|
|
1457
|
+
r = Z_DATA_ERROR;
|
|
1458
|
+
|
|
1459
|
+
that.bitb = b;
|
|
1460
|
+
that.bitk = k;
|
|
1461
|
+
z.avail_in = n;
|
|
1462
|
+
z.total_in += p - z.next_in_index;
|
|
1463
|
+
z.next_in_index = p;
|
|
1464
|
+
that.write = q;
|
|
1465
|
+
return that.inflate_flush(z, r);
|
|
1466
|
+
}
|
|
1467
|
+
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
|
|
1468
|
+
if (!blens || blens.length < t) {
|
|
1469
|
+
blens = []; // new Array(t);
|
|
1470
|
+
} else {
|
|
1471
|
+
for (i = 0; i < t; i++) {
|
|
1472
|
+
blens[i] = 0;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// {
|
|
1477
|
+
b >>>= (14);
|
|
1478
|
+
k -= (14);
|
|
1479
|
+
// }
|
|
1480
|
+
|
|
1481
|
+
index = 0;
|
|
1482
|
+
mode = BTREE;
|
|
1483
|
+
/* falls through */
|
|
1484
|
+
case BTREE:
|
|
1485
|
+
while (index < 4 + (table >>> 10)) {
|
|
1486
|
+
while (k < (3)) {
|
|
1487
|
+
if (n !== 0) {
|
|
1488
|
+
r = Z_OK;
|
|
1489
|
+
} else {
|
|
1490
|
+
that.bitb = b;
|
|
1491
|
+
that.bitk = k;
|
|
1492
|
+
z.avail_in = n;
|
|
1493
|
+
z.total_in += p - z.next_in_index;
|
|
1494
|
+
z.next_in_index = p;
|
|
1495
|
+
that.write = q;
|
|
1496
|
+
return that.inflate_flush(z, r);
|
|
1497
|
+
}
|
|
1498
|
+
n--;
|
|
1499
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
1500
|
+
k += 8;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
blens[border[index++]] = b & 7;
|
|
1504
|
+
|
|
1505
|
+
// {
|
|
1506
|
+
b >>>= (3);
|
|
1507
|
+
k -= (3);
|
|
1508
|
+
// }
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
while (index < 19) {
|
|
1512
|
+
blens[border[index++]] = 0;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
bb[0] = 7;
|
|
1516
|
+
t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
|
|
1517
|
+
if (t != Z_OK) {
|
|
1518
|
+
r = t;
|
|
1519
|
+
if (r == Z_DATA_ERROR) {
|
|
1520
|
+
blens = null;
|
|
1521
|
+
mode = BADBLOCKS;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
that.bitb = b;
|
|
1525
|
+
that.bitk = k;
|
|
1526
|
+
z.avail_in = n;
|
|
1527
|
+
z.total_in += p - z.next_in_index;
|
|
1528
|
+
z.next_in_index = p;
|
|
1529
|
+
that.write = q;
|
|
1530
|
+
return that.inflate_flush(z, r);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
index = 0;
|
|
1534
|
+
mode = DTREE;
|
|
1535
|
+
/* falls through */
|
|
1536
|
+
case DTREE:
|
|
1537
|
+
// eslint-disable-next-line no-constant-condition
|
|
1538
|
+
while (true) {
|
|
1539
|
+
t = table;
|
|
1540
|
+
if (index >= 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) {
|
|
1541
|
+
break;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
let j, c;
|
|
1545
|
+
|
|
1546
|
+
t = bb[0];
|
|
1547
|
+
|
|
1548
|
+
while (k < (t)) {
|
|
1549
|
+
if (n !== 0) {
|
|
1550
|
+
r = Z_OK;
|
|
1551
|
+
} else {
|
|
1552
|
+
that.bitb = b;
|
|
1553
|
+
that.bitk = k;
|
|
1554
|
+
z.avail_in = n;
|
|
1555
|
+
z.total_in += p - z.next_in_index;
|
|
1556
|
+
z.next_in_index = p;
|
|
1557
|
+
that.write = q;
|
|
1558
|
+
return that.inflate_flush(z, r);
|
|
1559
|
+
}
|
|
1560
|
+
n--;
|
|
1561
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
1562
|
+
k += 8;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// if (tb[0] == -1) {
|
|
1566
|
+
// System.err.println("null...");
|
|
1567
|
+
// }
|
|
1568
|
+
|
|
1569
|
+
t = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1];
|
|
1570
|
+
c = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2];
|
|
1571
|
+
|
|
1572
|
+
if (c < 16) {
|
|
1573
|
+
b >>>= (t);
|
|
1574
|
+
k -= (t);
|
|
1575
|
+
blens[index++] = c;
|
|
1576
|
+
} else { // c == 16..18
|
|
1577
|
+
i = c == 18 ? 7 : c - 14;
|
|
1578
|
+
j = c == 18 ? 11 : 3;
|
|
1579
|
+
|
|
1580
|
+
while (k < (t + i)) {
|
|
1581
|
+
if (n !== 0) {
|
|
1582
|
+
r = Z_OK;
|
|
1583
|
+
} else {
|
|
1584
|
+
that.bitb = b;
|
|
1585
|
+
that.bitk = k;
|
|
1586
|
+
z.avail_in = n;
|
|
1587
|
+
z.total_in += p - z.next_in_index;
|
|
1588
|
+
z.next_in_index = p;
|
|
1589
|
+
that.write = q;
|
|
1590
|
+
return that.inflate_flush(z, r);
|
|
1591
|
+
}
|
|
1592
|
+
n--;
|
|
1593
|
+
b |= (z.read_byte(p++) & 0xff) << k;
|
|
1594
|
+
k += 8;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
b >>>= (t);
|
|
1598
|
+
k -= (t);
|
|
1599
|
+
|
|
1600
|
+
j += (b & inflate_mask[i]);
|
|
1601
|
+
|
|
1602
|
+
b >>>= (i);
|
|
1603
|
+
k -= (i);
|
|
1604
|
+
|
|
1605
|
+
i = index;
|
|
1606
|
+
t = table;
|
|
1607
|
+
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {
|
|
1608
|
+
blens = null;
|
|
1609
|
+
mode = BADBLOCKS;
|
|
1610
|
+
z.msg = "invalid bit length repeat";
|
|
1611
|
+
r = Z_DATA_ERROR;
|
|
1612
|
+
|
|
1613
|
+
that.bitb = b;
|
|
1614
|
+
that.bitk = k;
|
|
1615
|
+
z.avail_in = n;
|
|
1616
|
+
z.total_in += p - z.next_in_index;
|
|
1617
|
+
z.next_in_index = p;
|
|
1618
|
+
that.write = q;
|
|
1619
|
+
return that.inflate_flush(z, r);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
c = c == 16 ? blens[i - 1] : 0;
|
|
1623
|
+
do {
|
|
1624
|
+
blens[i++] = c;
|
|
1625
|
+
} while (--j !== 0);
|
|
1626
|
+
index = i;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
tb[0] = -1;
|
|
1631
|
+
// {
|
|
1632
|
+
bl_ = []; // new Array(1);
|
|
1633
|
+
bd_ = []; // new Array(1);
|
|
1634
|
+
tl_ = []; // new Array(1);
|
|
1635
|
+
td_ = []; // new Array(1);
|
|
1636
|
+
bl_[0] = 9; // must be <= 9 for lookahead assumptions
|
|
1637
|
+
bd_[0] = 6; // must be <= 9 for lookahead assumptions
|
|
1638
|
+
|
|
1639
|
+
t = table;
|
|
1640
|
+
t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl_, bd_, tl_, td_, hufts, z);
|
|
1641
|
+
|
|
1642
|
+
if (t != Z_OK) {
|
|
1643
|
+
if (t == Z_DATA_ERROR) {
|
|
1644
|
+
blens = null;
|
|
1645
|
+
mode = BADBLOCKS;
|
|
1646
|
+
}
|
|
1647
|
+
r = t;
|
|
1648
|
+
|
|
1649
|
+
that.bitb = b;
|
|
1650
|
+
that.bitk = k;
|
|
1651
|
+
z.avail_in = n;
|
|
1652
|
+
z.total_in += p - z.next_in_index;
|
|
1653
|
+
z.next_in_index = p;
|
|
1654
|
+
that.write = q;
|
|
1655
|
+
return that.inflate_flush(z, r);
|
|
1656
|
+
}
|
|
1657
|
+
codes.init(bl_[0], bd_[0], hufts, tl_[0], hufts, td_[0]);
|
|
1658
|
+
// }
|
|
1659
|
+
mode = CODES;
|
|
1660
|
+
/* falls through */
|
|
1661
|
+
case CODES:
|
|
1662
|
+
that.bitb = b;
|
|
1663
|
+
that.bitk = k;
|
|
1664
|
+
z.avail_in = n;
|
|
1665
|
+
z.total_in += p - z.next_in_index;
|
|
1666
|
+
z.next_in_index = p;
|
|
1667
|
+
that.write = q;
|
|
1668
|
+
|
|
1669
|
+
if ((r = codes.proc(that, z, r)) != Z_STREAM_END) {
|
|
1670
|
+
return that.inflate_flush(z, r);
|
|
1671
|
+
}
|
|
1672
|
+
r = Z_OK;
|
|
1673
|
+
codes.free(z);
|
|
1674
|
+
|
|
1675
|
+
p = z.next_in_index;
|
|
1676
|
+
n = z.avail_in;
|
|
1677
|
+
b = that.bitb;
|
|
1678
|
+
k = that.bitk;
|
|
1679
|
+
q = that.write;
|
|
1680
|
+
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
|
|
1681
|
+
|
|
1682
|
+
if (last === 0) {
|
|
1683
|
+
mode = TYPE;
|
|
1684
|
+
break;
|
|
1685
|
+
}
|
|
1686
|
+
mode = DRY;
|
|
1687
|
+
/* falls through */
|
|
1688
|
+
case DRY:
|
|
1689
|
+
that.write = q;
|
|
1690
|
+
r = that.inflate_flush(z, r);
|
|
1691
|
+
q = that.write;
|
|
1692
|
+
m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
|
|
1693
|
+
if (that.read != that.write) {
|
|
1694
|
+
that.bitb = b;
|
|
1695
|
+
that.bitk = k;
|
|
1696
|
+
z.avail_in = n;
|
|
1697
|
+
z.total_in += p - z.next_in_index;
|
|
1698
|
+
z.next_in_index = p;
|
|
1699
|
+
that.write = q;
|
|
1700
|
+
return that.inflate_flush(z, r);
|
|
1701
|
+
}
|
|
1702
|
+
mode = DONELOCKS;
|
|
1703
|
+
/* falls through */
|
|
1704
|
+
case DONELOCKS:
|
|
1705
|
+
r = Z_STREAM_END;
|
|
1706
|
+
|
|
1707
|
+
that.bitb = b;
|
|
1708
|
+
that.bitk = k;
|
|
1709
|
+
z.avail_in = n;
|
|
1710
|
+
z.total_in += p - z.next_in_index;
|
|
1711
|
+
z.next_in_index = p;
|
|
1712
|
+
that.write = q;
|
|
1713
|
+
return that.inflate_flush(z, r);
|
|
1714
|
+
case BADBLOCKS:
|
|
1715
|
+
r = Z_DATA_ERROR;
|
|
1716
|
+
|
|
1717
|
+
that.bitb = b;
|
|
1718
|
+
that.bitk = k;
|
|
1719
|
+
z.avail_in = n;
|
|
1720
|
+
z.total_in += p - z.next_in_index;
|
|
1721
|
+
z.next_in_index = p;
|
|
1722
|
+
that.write = q;
|
|
1723
|
+
return that.inflate_flush(z, r);
|
|
1724
|
+
|
|
1725
|
+
default:
|
|
1726
|
+
r = Z_STREAM_ERROR;
|
|
1727
|
+
|
|
1728
|
+
that.bitb = b;
|
|
1729
|
+
that.bitk = k;
|
|
1730
|
+
z.avail_in = n;
|
|
1731
|
+
z.total_in += p - z.next_in_index;
|
|
1732
|
+
z.next_in_index = p;
|
|
1733
|
+
that.write = q;
|
|
1734
|
+
return that.inflate_flush(z, r);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
|
|
1739
|
+
that.free = function (z) {
|
|
1740
|
+
that.reset(z, null);
|
|
1741
|
+
that.win = null;
|
|
1742
|
+
hufts = null;
|
|
1743
|
+
// ZFREE(z, s);
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
that.set_dictionary = function (d, start, n) {
|
|
1747
|
+
that.win.set(d.subarray(start, start + n), 0);
|
|
1748
|
+
that.read = that.write = n;
|
|
1749
|
+
};
|
|
1750
|
+
|
|
1751
|
+
// Returns true if inflate is currently at the end of a block generated
|
|
1752
|
+
// by Z_SYNC_FLUSH or Z_FULL_FLUSH.
|
|
1753
|
+
that.sync_point = function () {
|
|
1754
|
+
return mode == LENS ? 1 : 0;
|
|
1755
|
+
};
|
|
1756
|
+
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
// Inflate
|
|
1760
|
+
|
|
1761
|
+
// preset dictionary flag in zlib header
|
|
1762
|
+
const PRESET_DICT = 0x20;
|
|
1763
|
+
|
|
1764
|
+
const Z_DEFLATED = 8;
|
|
1765
|
+
|
|
1766
|
+
const METHOD = 0; // waiting for method byte
|
|
1767
|
+
const FLAG = 1; // waiting for flag byte
|
|
1768
|
+
const DICT4 = 2; // four dictionary check bytes to go
|
|
1769
|
+
const DICT3 = 3; // three dictionary check bytes to go
|
|
1770
|
+
const DICT2 = 4; // two dictionary check bytes to go
|
|
1771
|
+
const DICT1 = 5; // one dictionary check byte to go
|
|
1772
|
+
const DICT0 = 6; // waiting for inflateSetDictionary
|
|
1773
|
+
const BLOCKS = 7; // decompressing blocks
|
|
1774
|
+
const DONE = 12; // finished check, done
|
|
1775
|
+
const BAD = 13; // got an error--stay here
|
|
1776
|
+
|
|
1777
|
+
const mark = [0, 0, 0xff, 0xff];
|
|
1778
|
+
|
|
1779
|
+
function Inflate() {
|
|
1780
|
+
const that = this;
|
|
1781
|
+
|
|
1782
|
+
that.mode = 0; // current inflate mode
|
|
1783
|
+
|
|
1784
|
+
// mode dependent information
|
|
1785
|
+
that.method = 0; // if FLAGS, method byte
|
|
1786
|
+
|
|
1787
|
+
// if CHECK, check values to compare
|
|
1788
|
+
that.was = [0]; // new Array(1); // computed check value
|
|
1789
|
+
that.need = 0; // stream check value
|
|
1790
|
+
|
|
1791
|
+
// if BAD, inflateSync's marker bytes count
|
|
1792
|
+
that.marker = 0;
|
|
1793
|
+
|
|
1794
|
+
// mode independent information
|
|
1795
|
+
that.wbits = 0; // log2(win size) (8..15, defaults to 15)
|
|
1796
|
+
|
|
1797
|
+
// this.blocks; // current inflate_blocks state
|
|
1798
|
+
|
|
1799
|
+
function inflateReset(z) {
|
|
1800
|
+
if (!z || !z.istate)
|
|
1801
|
+
return Z_STREAM_ERROR;
|
|
1802
|
+
|
|
1803
|
+
z.total_in = z.total_out = 0;
|
|
1804
|
+
z.msg = null;
|
|
1805
|
+
z.istate.mode = BLOCKS;
|
|
1806
|
+
z.istate.blocks.reset(z, null);
|
|
1807
|
+
return Z_OK;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
that.inflateEnd = function (z) {
|
|
1811
|
+
if (that.blocks)
|
|
1812
|
+
that.blocks.free(z);
|
|
1813
|
+
that.blocks = null;
|
|
1814
|
+
// ZFREE(z, z->state);
|
|
1815
|
+
return Z_OK;
|
|
1816
|
+
};
|
|
1817
|
+
|
|
1818
|
+
that.inflateInit = function (z, w) {
|
|
1819
|
+
z.msg = null;
|
|
1820
|
+
that.blocks = null;
|
|
1821
|
+
|
|
1822
|
+
// set win size
|
|
1823
|
+
if (w < 8 || w > 15) {
|
|
1824
|
+
that.inflateEnd(z);
|
|
1825
|
+
return Z_STREAM_ERROR;
|
|
1826
|
+
}
|
|
1827
|
+
that.wbits = w;
|
|
1828
|
+
|
|
1829
|
+
z.istate.blocks = new InfBlocks(z, 1 << w);
|
|
1830
|
+
|
|
1831
|
+
// reset state
|
|
1832
|
+
inflateReset(z);
|
|
1833
|
+
return Z_OK;
|
|
1834
|
+
};
|
|
1835
|
+
|
|
1836
|
+
that.inflate = function (z, f) {
|
|
1837
|
+
let r;
|
|
1838
|
+
let b;
|
|
1839
|
+
|
|
1840
|
+
if (!z || !z.istate || !z.next_in)
|
|
1841
|
+
return Z_STREAM_ERROR;
|
|
1842
|
+
const istate = z.istate;
|
|
1843
|
+
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
|
|
1844
|
+
r = Z_BUF_ERROR;
|
|
1845
|
+
// eslint-disable-next-line no-constant-condition
|
|
1846
|
+
while (true) {
|
|
1847
|
+
switch (istate.mode) {
|
|
1848
|
+
case METHOD:
|
|
1849
|
+
|
|
1850
|
+
if (z.avail_in === 0)
|
|
1851
|
+
return r;
|
|
1852
|
+
r = f;
|
|
1853
|
+
|
|
1854
|
+
z.avail_in--;
|
|
1855
|
+
z.total_in++;
|
|
1856
|
+
if (((istate.method = z.read_byte(z.next_in_index++)) & 0xf) != Z_DEFLATED) {
|
|
1857
|
+
istate.mode = BAD;
|
|
1858
|
+
z.msg = "unknown compression method";
|
|
1859
|
+
istate.marker = 5; // can't try inflateSync
|
|
1860
|
+
break;
|
|
1861
|
+
}
|
|
1862
|
+
if ((istate.method >> 4) + 8 > istate.wbits) {
|
|
1863
|
+
istate.mode = BAD;
|
|
1864
|
+
z.msg = "invalid win size";
|
|
1865
|
+
istate.marker = 5; // can't try inflateSync
|
|
1866
|
+
break;
|
|
1867
|
+
}
|
|
1868
|
+
istate.mode = FLAG;
|
|
1869
|
+
/* falls through */
|
|
1870
|
+
case FLAG:
|
|
1871
|
+
|
|
1872
|
+
if (z.avail_in === 0)
|
|
1873
|
+
return r;
|
|
1874
|
+
r = f;
|
|
1875
|
+
|
|
1876
|
+
z.avail_in--;
|
|
1877
|
+
z.total_in++;
|
|
1878
|
+
b = (z.read_byte(z.next_in_index++)) & 0xff;
|
|
1879
|
+
|
|
1880
|
+
if ((((istate.method << 8) + b) % 31) !== 0) {
|
|
1881
|
+
istate.mode = BAD;
|
|
1882
|
+
z.msg = "incorrect header check";
|
|
1883
|
+
istate.marker = 5; // can't try inflateSync
|
|
1884
|
+
break;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
if ((b & PRESET_DICT) === 0) {
|
|
1888
|
+
istate.mode = BLOCKS;
|
|
1889
|
+
break;
|
|
1890
|
+
}
|
|
1891
|
+
istate.mode = DICT4;
|
|
1892
|
+
/* falls through */
|
|
1893
|
+
case DICT4:
|
|
1894
|
+
|
|
1895
|
+
if (z.avail_in === 0)
|
|
1896
|
+
return r;
|
|
1897
|
+
r = f;
|
|
1898
|
+
|
|
1899
|
+
z.avail_in--;
|
|
1900
|
+
z.total_in++;
|
|
1901
|
+
istate.need = ((z.read_byte(z.next_in_index++) & 0xff) << 24) & 0xff000000;
|
|
1902
|
+
istate.mode = DICT3;
|
|
1903
|
+
/* falls through */
|
|
1904
|
+
case DICT3:
|
|
1905
|
+
|
|
1906
|
+
if (z.avail_in === 0)
|
|
1907
|
+
return r;
|
|
1908
|
+
r = f;
|
|
1909
|
+
|
|
1910
|
+
z.avail_in--;
|
|
1911
|
+
z.total_in++;
|
|
1912
|
+
istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 16) & 0xff0000;
|
|
1913
|
+
istate.mode = DICT2;
|
|
1914
|
+
/* falls through */
|
|
1915
|
+
case DICT2:
|
|
1916
|
+
|
|
1917
|
+
if (z.avail_in === 0)
|
|
1918
|
+
return r;
|
|
1919
|
+
r = f;
|
|
1920
|
+
|
|
1921
|
+
z.avail_in--;
|
|
1922
|
+
z.total_in++;
|
|
1923
|
+
istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 8) & 0xff00;
|
|
1924
|
+
istate.mode = DICT1;
|
|
1925
|
+
/* falls through */
|
|
1926
|
+
case DICT1:
|
|
1927
|
+
|
|
1928
|
+
if (z.avail_in === 0)
|
|
1929
|
+
return r;
|
|
1930
|
+
r = f;
|
|
1931
|
+
|
|
1932
|
+
z.avail_in--;
|
|
1933
|
+
z.total_in++;
|
|
1934
|
+
istate.need += (z.read_byte(z.next_in_index++) & 0xff);
|
|
1935
|
+
istate.mode = DICT0;
|
|
1936
|
+
return Z_NEED_DICT;
|
|
1937
|
+
case DICT0:
|
|
1938
|
+
istate.mode = BAD;
|
|
1939
|
+
z.msg = "need dictionary";
|
|
1940
|
+
istate.marker = 0; // can try inflateSync
|
|
1941
|
+
return Z_STREAM_ERROR;
|
|
1942
|
+
case BLOCKS:
|
|
1943
|
+
|
|
1944
|
+
r = istate.blocks.proc(z, r);
|
|
1945
|
+
if (r == Z_DATA_ERROR) {
|
|
1946
|
+
istate.mode = BAD;
|
|
1947
|
+
istate.marker = 0; // can try inflateSync
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
if (r == Z_OK) {
|
|
1951
|
+
r = f;
|
|
1952
|
+
}
|
|
1953
|
+
if (r != Z_STREAM_END) {
|
|
1954
|
+
return r;
|
|
1955
|
+
}
|
|
1956
|
+
r = f;
|
|
1957
|
+
istate.blocks.reset(z, istate.was);
|
|
1958
|
+
istate.mode = DONE;
|
|
1959
|
+
/* falls through */
|
|
1960
|
+
case DONE:
|
|
1961
|
+
z.avail_in = 0;
|
|
1962
|
+
return Z_STREAM_END;
|
|
1963
|
+
case BAD:
|
|
1964
|
+
return Z_DATA_ERROR;
|
|
1965
|
+
default:
|
|
1966
|
+
return Z_STREAM_ERROR;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
};
|
|
1970
|
+
|
|
1971
|
+
that.inflateSetDictionary = function (z, dictionary, dictLength) {
|
|
1972
|
+
let index = 0, length = dictLength;
|
|
1973
|
+
if (!z || !z.istate || z.istate.mode != DICT0)
|
|
1974
|
+
return Z_STREAM_ERROR;
|
|
1975
|
+
const istate = z.istate;
|
|
1976
|
+
if (length >= (1 << istate.wbits)) {
|
|
1977
|
+
length = (1 << istate.wbits) - 1;
|
|
1978
|
+
index = dictLength - length;
|
|
1979
|
+
}
|
|
1980
|
+
istate.blocks.set_dictionary(dictionary, index, length);
|
|
1981
|
+
istate.mode = BLOCKS;
|
|
1982
|
+
return Z_OK;
|
|
1983
|
+
};
|
|
1984
|
+
|
|
1985
|
+
that.inflateSync = function (z) {
|
|
1986
|
+
let n; // number of bytes to look at
|
|
1987
|
+
let p; // pointer to bytes
|
|
1988
|
+
let m; // number of marker bytes found in a row
|
|
1989
|
+
let r, w; // temporaries to save total_in and total_out
|
|
1990
|
+
|
|
1991
|
+
// set up
|
|
1992
|
+
if (!z || !z.istate)
|
|
1993
|
+
return Z_STREAM_ERROR;
|
|
1994
|
+
const istate = z.istate;
|
|
1995
|
+
if (istate.mode != BAD) {
|
|
1996
|
+
istate.mode = BAD;
|
|
1997
|
+
istate.marker = 0;
|
|
1998
|
+
}
|
|
1999
|
+
if ((n = z.avail_in) === 0)
|
|
2000
|
+
return Z_BUF_ERROR;
|
|
2001
|
+
p = z.next_in_index;
|
|
2002
|
+
m = istate.marker;
|
|
2003
|
+
|
|
2004
|
+
// search
|
|
2005
|
+
while (n !== 0 && m < 4) {
|
|
2006
|
+
if (z.read_byte(p) == mark[m]) {
|
|
2007
|
+
m++;
|
|
2008
|
+
} else if (z.read_byte(p) !== 0) {
|
|
2009
|
+
m = 0;
|
|
2010
|
+
} else {
|
|
2011
|
+
m = 4 - m;
|
|
2012
|
+
}
|
|
2013
|
+
p++;
|
|
2014
|
+
n--;
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
// restore
|
|
2018
|
+
z.total_in += p - z.next_in_index;
|
|
2019
|
+
z.next_in_index = p;
|
|
2020
|
+
z.avail_in = n;
|
|
2021
|
+
istate.marker = m;
|
|
2022
|
+
|
|
2023
|
+
// return no joy or set up to restart on a new block
|
|
2024
|
+
if (m != 4) {
|
|
2025
|
+
return Z_DATA_ERROR;
|
|
2026
|
+
}
|
|
2027
|
+
r = z.total_in;
|
|
2028
|
+
w = z.total_out;
|
|
2029
|
+
inflateReset(z);
|
|
2030
|
+
z.total_in = r;
|
|
2031
|
+
z.total_out = w;
|
|
2032
|
+
istate.mode = BLOCKS;
|
|
2033
|
+
return Z_OK;
|
|
2034
|
+
};
|
|
2035
|
+
|
|
2036
|
+
// Returns true if inflate is currently at the end of a block generated
|
|
2037
|
+
// by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
|
|
2038
|
+
// implementation to provide an additional safety check. PPP uses
|
|
2039
|
+
// Z_SYNC_FLUSH
|
|
2040
|
+
// but removes the length bytes of the resulting empty stored block. When
|
|
2041
|
+
// decompressing, PPP checks that at the end of input packet, inflate is
|
|
2042
|
+
// waiting for these length bytes.
|
|
2043
|
+
that.inflateSyncPoint = function (z) {
|
|
2044
|
+
if (!z || !z.istate || !z.istate.blocks)
|
|
2045
|
+
return Z_STREAM_ERROR;
|
|
2046
|
+
return z.istate.blocks.sync_point();
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
// ZStream
|
|
2051
|
+
|
|
2052
|
+
function ZStream() {
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
ZStream.prototype = {
|
|
2056
|
+
inflateInit(bits) {
|
|
2057
|
+
const that = this;
|
|
2058
|
+
that.istate = new Inflate();
|
|
2059
|
+
if (!bits)
|
|
2060
|
+
bits = MAX_BITS;
|
|
2061
|
+
return that.istate.inflateInit(that, bits);
|
|
2062
|
+
},
|
|
2063
|
+
|
|
2064
|
+
inflate(f) {
|
|
2065
|
+
const that = this;
|
|
2066
|
+
if (!that.istate)
|
|
2067
|
+
return Z_STREAM_ERROR;
|
|
2068
|
+
return that.istate.inflate(that, f);
|
|
2069
|
+
},
|
|
2070
|
+
|
|
2071
|
+
inflateEnd() {
|
|
2072
|
+
const that = this;
|
|
2073
|
+
if (!that.istate)
|
|
2074
|
+
return Z_STREAM_ERROR;
|
|
2075
|
+
const ret = that.istate.inflateEnd(that);
|
|
2076
|
+
that.istate = null;
|
|
2077
|
+
return ret;
|
|
2078
|
+
},
|
|
2079
|
+
|
|
2080
|
+
inflateSync() {
|
|
2081
|
+
const that = this;
|
|
2082
|
+
if (!that.istate)
|
|
2083
|
+
return Z_STREAM_ERROR;
|
|
2084
|
+
return that.istate.inflateSync(that);
|
|
2085
|
+
},
|
|
2086
|
+
inflateSetDictionary(dictionary, dictLength) {
|
|
2087
|
+
const that = this;
|
|
2088
|
+
if (!that.istate)
|
|
2089
|
+
return Z_STREAM_ERROR;
|
|
2090
|
+
return that.istate.inflateSetDictionary(that, dictionary, dictLength);
|
|
2091
|
+
},
|
|
2092
|
+
read_byte(start) {
|
|
2093
|
+
const that = this;
|
|
2094
|
+
return that.next_in[start];
|
|
2095
|
+
},
|
|
2096
|
+
read_buf(start, size) {
|
|
2097
|
+
const that = this;
|
|
2098
|
+
return that.next_in.subarray(start, start + size);
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
|
|
2102
|
+
// Inflater
|
|
2103
|
+
|
|
2104
|
+
function ZipInflate(options) {
|
|
2105
|
+
const that = this;
|
|
2106
|
+
const z = new ZStream();
|
|
2107
|
+
const bufsize = options && options.chunkSize ? Math.floor(options.chunkSize * 2) : 128 * 1024;
|
|
2108
|
+
const flush = Z_NO_FLUSH;
|
|
2109
|
+
const buf = new Uint8Array(bufsize);
|
|
2110
|
+
let nomoreinput = false;
|
|
2111
|
+
|
|
2112
|
+
z.inflateInit();
|
|
2113
|
+
z.next_out = buf;
|
|
2114
|
+
|
|
2115
|
+
that.append = function (data, onprogress) {
|
|
2116
|
+
const buffers = [];
|
|
2117
|
+
let err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0;
|
|
2118
|
+
if (data.length === 0)
|
|
2119
|
+
return;
|
|
2120
|
+
z.next_in_index = 0;
|
|
2121
|
+
z.next_in = data;
|
|
2122
|
+
z.avail_in = data.length;
|
|
2123
|
+
do {
|
|
2124
|
+
z.next_out_index = 0;
|
|
2125
|
+
z.avail_out = bufsize;
|
|
2126
|
+
if ((z.avail_in === 0) && (!nomoreinput)) { // if buffer is empty and more input is available, refill it
|
|
2127
|
+
z.next_in_index = 0;
|
|
2128
|
+
nomoreinput = true;
|
|
2129
|
+
}
|
|
2130
|
+
err = z.inflate(flush);
|
|
2131
|
+
if (nomoreinput && (err === Z_BUF_ERROR)) {
|
|
2132
|
+
if (z.avail_in !== 0)
|
|
2133
|
+
throw new Error("inflating: bad input");
|
|
2134
|
+
} else if (err !== Z_OK && err !== Z_STREAM_END)
|
|
2135
|
+
throw new Error("inflating: " + z.msg);
|
|
2136
|
+
if ((nomoreinput || err === Z_STREAM_END) && (z.avail_in === data.length))
|
|
2137
|
+
throw new Error("inflating: bad input");
|
|
2138
|
+
if (z.next_out_index)
|
|
2139
|
+
if (z.next_out_index === bufsize)
|
|
2140
|
+
buffers.push(new Uint8Array(buf));
|
|
2141
|
+
else
|
|
2142
|
+
buffers.push(buf.subarray(0, z.next_out_index));
|
|
2143
|
+
bufferSize += z.next_out_index;
|
|
2144
|
+
if (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) {
|
|
2145
|
+
onprogress(z.next_in_index);
|
|
2146
|
+
lastIndex = z.next_in_index;
|
|
2147
|
+
}
|
|
2148
|
+
} while (z.avail_in > 0 || z.avail_out === 0);
|
|
2149
|
+
if (buffers.length > 1) {
|
|
2150
|
+
array = new Uint8Array(bufferSize);
|
|
2151
|
+
buffers.forEach(function (chunk) {
|
|
2152
|
+
array.set(chunk, bufferIndex);
|
|
2153
|
+
bufferIndex += chunk.length;
|
|
2154
|
+
});
|
|
2155
|
+
} else {
|
|
2156
|
+
array = buffers[0] ? new Uint8Array(buffers[0]) : new Uint8Array();
|
|
2157
|
+
}
|
|
2158
|
+
return array;
|
|
2159
|
+
};
|
|
2160
|
+
that.flush = function () {
|
|
2161
|
+
z.inflateEnd();
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
export {
|
|
2166
|
+
ZipInflate as Inflate
|
|
2167
|
+
};
|