@mtkruto/node 0.0.6

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.
Files changed (167) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +1 -0
  3. package/esm/_dnt.shims.js +68 -0
  4. package/esm/client/client.js +169 -0
  5. package/esm/client/client_abstract.js +51 -0
  6. package/esm/client/client_plain.js +112 -0
  7. package/esm/connection/connection.js +2 -0
  8. package/esm/connection/connection_web_socket.js +90 -0
  9. package/esm/constants.js +60 -0
  10. package/esm/deps/deno.land/std@0.186.0/fmt/colors.js +474 -0
  11. package/esm/deps/deno.land/std@0.186.0/testing/_diff.js +311 -0
  12. package/esm/deps/deno.land/std@0.186.0/testing/_format.js +23 -0
  13. package/esm/deps/deno.land/std@0.186.0/testing/asserts.js +633 -0
  14. package/esm/deps/deno.land/x/crc32@v0.2.0/mod.js +105 -0
  15. package/esm/deps/deno.land/x/tgcrypto@0.1.1/mod.js +68 -0
  16. package/esm/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1127 -0
  17. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +239 -0
  18. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +10 -0
  19. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +139 -0
  20. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +176 -0
  21. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +2 -0
  22. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +19 -0
  23. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +25 -0
  24. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1941 -0
  25. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +85 -0
  26. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +321 -0
  27. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1658 -0
  28. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +355 -0
  29. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +11 -0
  30. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +42 -0
  31. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1107 -0
  32. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +86 -0
  33. package/esm/deps.js +4 -0
  34. package/esm/mod.js +4 -0
  35. package/esm/package.json +3 -0
  36. package/esm/tl/0_tl_raw_reader.js +62 -0
  37. package/esm/tl/0_tl_raw_writer.js +60 -0
  38. package/esm/tl/1_tl_object.js +149 -0
  39. package/esm/tl/2_types.js +48220 -0
  40. package/esm/tl/3_functions.js +19856 -0
  41. package/esm/tl/3_tl_object_deserializer.js +72 -0
  42. package/esm/tl/3_tl_reader.js +16 -0
  43. package/esm/tl/3_tl_writer.js +7 -0
  44. package/esm/tl/4_rpc_result.js +27 -0
  45. package/esm/tl/5_message.js +54 -0
  46. package/esm/tl/6_message_container.js +35 -0
  47. package/esm/transport/transport.js +32 -0
  48. package/esm/transport/transport_intermediate.js +56 -0
  49. package/esm/transport/transport_provider.js +23 -0
  50. package/esm/types.js +1 -0
  51. package/esm/utilities/0_bigint.js +37 -0
  52. package/esm/utilities/0_buffer.js +33 -0
  53. package/esm/utilities/0_crypto.js +35 -0
  54. package/esm/utilities/0_hash.js +7 -0
  55. package/esm/utilities/1_auth.js +29 -0
  56. package/esm/utilities/1_message.js +94 -0
  57. package/esm/utilities/1_obfuscation.js +33 -0
  58. package/package.json +40 -0
  59. package/script/_dnt.shims.js +77 -0
  60. package/script/client/client.js +173 -0
  61. package/script/client/client_abstract.js +55 -0
  62. package/script/client/client_plain.js +116 -0
  63. package/script/connection/connection.js +6 -0
  64. package/script/connection/connection_web_socket.js +117 -0
  65. package/script/constants.js +63 -0
  66. package/script/deps/deno.land/std@0.186.0/fmt/colors.js +548 -0
  67. package/script/deps/deno.land/std@0.186.0/testing/_diff.js +317 -0
  68. package/script/deps/deno.land/std@0.186.0/testing/_format.js +50 -0
  69. package/script/deps/deno.land/std@0.186.0/testing/asserts.js +659 -0
  70. package/script/deps/deno.land/x/crc32@v0.2.0/mod.js +113 -0
  71. package/script/deps/deno.land/x/tgcrypto@0.1.1/mod.js +82 -0
  72. package/script/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.js +1152 -0
  73. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.js +271 -0
  74. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.js +14 -0
  75. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.js +172 -0
  76. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.js +208 -0
  77. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.js +18 -0
  78. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.js +22 -0
  79. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.js +30 -0
  80. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.js +1976 -0
  81. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.js +88 -0
  82. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.js +324 -0
  83. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.js +1674 -0
  84. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.js +358 -0
  85. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.js +14 -0
  86. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.js +44 -0
  87. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.js +1115 -0
  88. package/script/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.js +89 -0
  89. package/script/deps.js +30 -0
  90. package/script/mod.js +32 -0
  91. package/script/package.json +3 -0
  92. package/script/tl/0_tl_raw_reader.js +66 -0
  93. package/script/tl/0_tl_raw_writer.js +64 -0
  94. package/script/tl/1_tl_object.js +156 -0
  95. package/script/tl/2_types.js +49824 -0
  96. package/script/tl/3_functions.js +20413 -0
  97. package/script/tl/3_tl_object_deserializer.js +76 -0
  98. package/script/tl/3_tl_reader.js +20 -0
  99. package/script/tl/3_tl_writer.js +11 -0
  100. package/script/tl/4_rpc_result.js +31 -0
  101. package/script/tl/5_message.js +58 -0
  102. package/script/tl/6_message_container.js +39 -0
  103. package/script/transport/transport.js +36 -0
  104. package/script/transport/transport_intermediate.js +60 -0
  105. package/script/transport/transport_provider.js +27 -0
  106. package/script/types.js +2 -0
  107. package/script/utilities/0_bigint.js +67 -0
  108. package/script/utilities/0_buffer.js +38 -0
  109. package/script/utilities/0_crypto.js +39 -0
  110. package/script/utilities/0_hash.js +35 -0
  111. package/script/utilities/1_auth.js +56 -0
  112. package/script/utilities/1_message.js +102 -0
  113. package/script/utilities/1_obfuscation.js +60 -0
  114. package/types/_dnt.shims.d.ts +10 -0
  115. package/types/client/client.d.ts +19 -0
  116. package/types/client/client_abstract.d.ts +20 -0
  117. package/types/client/client_plain.d.ts +10 -0
  118. package/types/connection/connection.d.ts +7 -0
  119. package/types/connection/connection_web_socket.d.ts +13 -0
  120. package/types/constants.d.ts +2 -0
  121. package/types/deps/deno.land/std@0.186.0/fmt/colors.d.ts +270 -0
  122. package/types/deps/deno.land/std@0.186.0/testing/_diff.d.ts +26 -0
  123. package/types/deps/deno.land/std@0.186.0/testing/_format.d.ts +1 -0
  124. package/types/deps/deno.land/std@0.186.0/testing/asserts.d.ts +284 -0
  125. package/types/deps/deno.land/x/crc32@v0.2.0/mod.d.ts +15 -0
  126. package/types/deps/deno.land/x/tgcrypto@0.1.1/mod.d.ts +47 -0
  127. package/types/deps/deno.land/x/tgcrypto@0.1.1/tgcrypto.d.ts +2 -0
  128. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/gzip/gzip.d.ts +16 -0
  129. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/utils/uint8.d.ts +1 -0
  130. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/deflate.d.ts +29 -0
  131. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/inflate.d.ts +23 -0
  132. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/mod.d.ts +2 -0
  133. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/adler32.d.ts +1 -0
  134. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/crc32.d.ts +2 -0
  135. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/deflate.d.ts +78 -0
  136. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/gzheader.d.ts +12 -0
  137. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inffast.d.ts +1 -0
  138. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inflate.d.ts +47 -0
  139. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/inftrees.d.ts +1 -0
  140. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/messages.d.ts +12 -0
  141. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/status.d.ts +30 -0
  142. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/trees.d.ts +5 -0
  143. package/types/deps/raw.githubusercontent.com/MTKruto/compress/master/zlib/zlib/zstream.d.ts +14 -0
  144. package/types/deps.d.ts +4 -0
  145. package/types/mod.d.ts +4 -0
  146. package/types/tl/0_tl_raw_reader.d.ts +13 -0
  147. package/types/tl/0_tl_raw_writer.d.ts +13 -0
  148. package/types/tl/1_tl_object.d.ts +36 -0
  149. package/types/tl/2_types.d.ts +14815 -0
  150. package/types/tl/3_functions.d.ts +6122 -0
  151. package/types/tl/3_tl_object_deserializer.d.ts +3 -0
  152. package/types/tl/3_tl_reader.d.ts +4 -0
  153. package/types/tl/3_tl_writer.d.ts +5 -0
  154. package/types/tl/4_rpc_result.d.ts +8 -0
  155. package/types/tl/5_message.d.ts +11 -0
  156. package/types/tl/6_message_container.d.ts +9 -0
  157. package/types/transport/transport.d.ts +15 -0
  158. package/types/transport/transport_intermediate.d.ts +11 -0
  159. package/types/transport/transport_provider.d.ts +12 -0
  160. package/types/types.d.ts +1 -0
  161. package/types/utilities/0_bigint.d.ts +4 -0
  162. package/types/utilities/0_buffer.d.ts +2 -0
  163. package/types/utilities/0_crypto.d.ts +8 -0
  164. package/types/utilities/0_hash.d.ts +2 -0
  165. package/types/utilities/1_auth.d.ts +1 -0
  166. package/types/utilities/1_message.d.ts +10 -0
  167. package/types/utilities/1_obfuscation.d.ts +6 -0
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.checkTail = exports.checkHeader = exports.gunzip = exports.gzip = exports.getHeader = exports.putLong = exports.DEFAULT_LEVEL = void 0;
27
+ const dntShim = __importStar(require("../../../../../../_dnt.shims.js"));
28
+ const mod_js_1 = require("../../../../../deno.land/x/crc32@v0.2.0/mod.js");
29
+ /** very fast */
30
+ const mod_js_2 = require("../zlib/mod.js");
31
+ /** slow */
32
+ // import { deflateRaw, inflateRaw } from "../deflate/mod.ts";
33
+ // magic numbers marking this file as GZIP
34
+ const ID1 = 0x1F;
35
+ const ID2 = 0x8B;
36
+ const compressionMethods = {
37
+ "deflate": 8,
38
+ };
39
+ const possibleFlags = {
40
+ "FTEXT": 0x01,
41
+ "FHCRC": 0x02,
42
+ "FEXTRA": 0x04,
43
+ "FNAME": 0x08,
44
+ "FCOMMENT": 0x10,
45
+ };
46
+ // const osMap = {
47
+ // "fat": 0, // FAT file system (DOS, OS/2, NT) + PKZIPW 2.50 VFAT, NTFS
48
+ // "amiga": 1, // Amiga
49
+ // "vmz": 2, // VMS (VAX or Alpha AXP)
50
+ // "unix": 3, // Unix
51
+ // "vm/cms": 4, // VM/CMS
52
+ // "atari": 5, // Atari
53
+ // "hpfs": 6, // HPFS file system (OS/2, NT 3.x)
54
+ // "macintosh": 7, // Macintosh
55
+ // "z-system": 8, // Z-System
56
+ // "cplm": 9, // CP/M
57
+ // "tops-20": 10, // TOPS-20
58
+ // "ntfs": 11, // NTFS file system (NT)
59
+ // "qdos": 12, // SMS/QDOS
60
+ // "acorn": 13, // Acorn RISC OS
61
+ // "vfat": 14, // VFAT file system (Win95, NT)
62
+ // "vms": 15, // MVS (code also taken for PRIMOS)
63
+ // "beos": 16, // BeOS (BeBox or PowerMac)
64
+ // "tandem": 17, // Tandem/NSK
65
+ // "theos": 18, // THEOS
66
+ // };
67
+ const os = {
68
+ "darwin": 3,
69
+ "linux": 3,
70
+ "windows": 0,
71
+ };
72
+ // @ts-ignore
73
+ const osCode = os[dntShim.dntGlobalThis["Deno"]?.build?.os] ?? 255;
74
+ exports.DEFAULT_LEVEL = 6;
75
+ function putByte(n, arr) {
76
+ arr.push(n & 0xFF);
77
+ }
78
+ // LSB first
79
+ function putShort(n, arr) {
80
+ arr.push(n & 0xFF);
81
+ arr.push(n >>> 8);
82
+ }
83
+ // LSB first
84
+ function putLong(n, arr) {
85
+ putShort(n & 0xffff, arr);
86
+ putShort(n >>> 16, arr);
87
+ }
88
+ exports.putLong = putLong;
89
+ function putString(s, arr) {
90
+ for (let i = 0, len = s.length; i < len; i += 1) {
91
+ putByte(s.charCodeAt(i), arr);
92
+ }
93
+ }
94
+ function readByte(arr) {
95
+ return arr.shift();
96
+ }
97
+ function readShort(arr) {
98
+ return arr.shift() | (arr.shift() << 8);
99
+ }
100
+ function readLong(arr) {
101
+ const n1 = readShort(arr);
102
+ let n2 = readShort(arr);
103
+ // JavaScript can't handle bits in the position 32
104
+ // we'll emulate this by removing the left-most bit (if it exists)
105
+ // and add it back in via multiplication, which does work
106
+ if (n2 > 32768) {
107
+ n2 -= 32768;
108
+ return ((n2 << 16) | n1) + 32768 * Math.pow(2, 16);
109
+ }
110
+ return (n2 << 16) | n1;
111
+ }
112
+ function readString(arr) {
113
+ const charArr = [];
114
+ // turn all bytes into chars until the terminating null
115
+ while (arr[0] !== 0) {
116
+ charArr.push(String.fromCharCode(arr.shift()));
117
+ }
118
+ // throw away terminating null
119
+ arr.shift();
120
+ // join all characters into a cohesive string
121
+ return charArr.join("");
122
+ }
123
+ function readBytes(arr, n) {
124
+ const ret = [];
125
+ for (let i = 0; i < n; i += 1) {
126
+ ret.push(arr.shift());
127
+ }
128
+ return ret;
129
+ }
130
+ function getHeader(options = {}) {
131
+ let flags = 0;
132
+ const level = options.level ?? exports.DEFAULT_LEVEL;
133
+ const out = [];
134
+ putByte(ID1, out);
135
+ putByte(ID2, out);
136
+ putByte(compressionMethods["deflate"], out);
137
+ if (options.name) {
138
+ flags |= possibleFlags["FNAME"];
139
+ }
140
+ putByte(flags, out);
141
+ putLong(options.timestamp ?? Math.floor(Date.now() / 1000), out);
142
+ // put deflate args (extra flags)
143
+ if (level === 1) {
144
+ // fastest algorithm
145
+ putByte(4, out);
146
+ }
147
+ else if (level === 9) {
148
+ // maximum compression (fastest algorithm)
149
+ putByte(2, out);
150
+ }
151
+ else {
152
+ putByte(0, out);
153
+ }
154
+ // OS identifier
155
+ putByte(osCode, out);
156
+ if (options.name) {
157
+ // ignore the directory part
158
+ putString(options.name.substring(options.name.lastIndexOf("/") + 1), out);
159
+ // terminating null
160
+ putByte(0, out);
161
+ }
162
+ return new Uint8Array(out);
163
+ }
164
+ exports.getHeader = getHeader;
165
+ function gzip(bytes, options = {}) {
166
+ let flags = 0;
167
+ const level = options.level ?? exports.DEFAULT_LEVEL;
168
+ const out = [];
169
+ putByte(ID1, out);
170
+ putByte(ID2, out);
171
+ putByte(compressionMethods["deflate"], out);
172
+ if (options.name) {
173
+ flags |= possibleFlags["FNAME"];
174
+ }
175
+ putByte(flags, out);
176
+ putLong(options.timestamp ?? Math.floor(Date.now() / 1000), out);
177
+ // put deflate args (extra flags)
178
+ if (level === 1) {
179
+ // fastest algorithm
180
+ putByte(4, out);
181
+ }
182
+ else if (level === 9) {
183
+ // maximum compression (fastest algorithm)
184
+ putByte(2, out);
185
+ }
186
+ else {
187
+ putByte(0, out);
188
+ }
189
+ // OS identifier
190
+ putByte(osCode, out);
191
+ if (options.name) {
192
+ // ignore the directory part
193
+ putString(options.name.substring(options.name.lastIndexOf("/") + 1), out);
194
+ // terminating null
195
+ putByte(0, out);
196
+ }
197
+ (0, mod_js_2.deflateRaw)(bytes).forEach(function (byte) {
198
+ putByte(byte, out);
199
+ });
200
+ // import { deflateRaw, inflateRaw } from "../deflate/mod.ts";
201
+ // deflateRaw(bytes, level).forEach(function (byte) {
202
+ // putByte(byte, out);
203
+ // });
204
+ putLong(parseInt((0, mod_js_1.crc32)(bytes), 16), out);
205
+ putLong(bytes.length, out);
206
+ return new Uint8Array(out);
207
+ }
208
+ exports.gzip = gzip;
209
+ function gunzip(bytes) {
210
+ const arr = Array.from(bytes);
211
+ checkHeader(arr);
212
+ // give deflate everything but the last 8 bytes
213
+ // the last 8 bytes are for the CRC32 checksum and filesize
214
+ const res = (0, mod_js_2.inflateRaw)(new Uint8Array(arr.splice(0, arr.length - 8)));
215
+ // if (flags & possibleFlags["FTEXT"]) {
216
+ // res = Array.prototype.map.call(res, function (byte) {
217
+ // return String.fromCharCode(byte);
218
+ // }).join("");
219
+ // }
220
+ const crc = readLong(arr) >>> 0;
221
+ if (crc !== parseInt((0, mod_js_1.crc32)(res), 16)) {
222
+ throw "Checksum does not match";
223
+ }
224
+ const size = readLong(arr);
225
+ if (size !== res.length) {
226
+ throw "Size of decompressed file not correct";
227
+ }
228
+ return res;
229
+ }
230
+ exports.gunzip = gunzip;
231
+ function checkHeader(arr) {
232
+ // check the first two bytes for the magic numbers
233
+ if (readByte(arr) !== ID1 || readByte(arr) !== ID2) {
234
+ throw "Not a GZIP file";
235
+ }
236
+ if (readByte(arr) !== 8) {
237
+ throw "Unsupported compression method";
238
+ }
239
+ const flags = readByte(arr);
240
+ readLong(arr); // mtime
241
+ readByte(arr); // xFlags
242
+ readByte(arr); // os, throw away
243
+ // just throw away the bytes for now
244
+ if (flags & possibleFlags["FEXTRA"]) {
245
+ const t = readShort(arr);
246
+ readBytes(arr, t);
247
+ }
248
+ // just throw away for now
249
+ if (flags & possibleFlags["FNAME"]) {
250
+ readString(arr);
251
+ }
252
+ // just throw away for now
253
+ if (flags & possibleFlags["FCOMMENT"]) {
254
+ readString(arr);
255
+ }
256
+ // just throw away for now
257
+ if (flags & possibleFlags["FHCRC"]) {
258
+ readShort(arr);
259
+ }
260
+ }
261
+ exports.checkHeader = checkHeader;
262
+ function checkTail(arr) {
263
+ const tail = arr.splice(arr.length - 8);
264
+ const crc32 = readLong(tail) >>> 0;
265
+ const size = readLong(tail);
266
+ return {
267
+ crc32,
268
+ size,
269
+ };
270
+ }
271
+ exports.checkTail = checkTail;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.concatUint8Array = void 0;
4
+ function concatUint8Array(arr) {
5
+ const length = arr.reduce((pre, next) => pre + next.length, 0);
6
+ const result = new Uint8Array(length);
7
+ let offset = 0;
8
+ for (const v of arr) {
9
+ result.set(v, offset);
10
+ offset += v.length;
11
+ }
12
+ return result;
13
+ }
14
+ exports.concatUint8Array = concatUint8Array;
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.gzip = exports.deflateRaw = exports.deflate = exports.Deflate = void 0;
30
+ // from https://github.com/nodeca/pako
31
+ const zlibDeflate = __importStar(require("./zlib/deflate.js"));
32
+ const uint8_js_1 = require("../utils/uint8.js");
33
+ const messages_js_1 = require("./zlib/messages.js");
34
+ const zstream_js_1 = __importDefault(require("./zlib/zstream.js"));
35
+ const status_js_1 = __importDefault(require("./zlib/status.js"));
36
+ class Deflate {
37
+ constructor(options = {}) {
38
+ Object.defineProperty(this, "err", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: 0
43
+ }); // error code, if happens (0 = Z_OK)
44
+ Object.defineProperty(this, "msg", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: ""
49
+ }); // error message
50
+ Object.defineProperty(this, "ended", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: false
55
+ }); // used to avoid multiple onEnd() calls
56
+ Object.defineProperty(this, "strm", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: void 0
61
+ });
62
+ Object.defineProperty(this, "_dict_set", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: false
67
+ });
68
+ Object.defineProperty(this, "options", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: void 0
73
+ });
74
+ this.options = Object.assign({
75
+ level: status_js_1.default.Z_DEFAULT_COMPRESSION,
76
+ method: status_js_1.default.Z_DEFLATED,
77
+ chunkSize: 16384,
78
+ windowBits: 15,
79
+ memLevel: 8,
80
+ strategy: status_js_1.default.Z_DEFAULT_STRATEGY,
81
+ to: "",
82
+ }, options);
83
+ const opt = this.options;
84
+ if (opt.raw && (opt.windowBits > 0)) {
85
+ opt.windowBits = -opt.windowBits;
86
+ }
87
+ else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {
88
+ opt.windowBits += 16;
89
+ }
90
+ this.strm = new zstream_js_1.default();
91
+ this.strm.avail_out = 0;
92
+ let status = zlibDeflate.deflateInit2(this.strm, opt.level, opt.method, opt.windowBits, opt.memLevel, opt.strategy);
93
+ if (status !== status_js_1.default.Z_OK) {
94
+ throw new Error(messages_js_1.message[status]);
95
+ }
96
+ if (opt.header) {
97
+ zlibDeflate.deflateSetHeader(this.strm, opt.header);
98
+ }
99
+ if (opt.dictionary) {
100
+ status = zlibDeflate.deflateSetDictionary(this.strm, opt.dictionary);
101
+ if (status !== status_js_1.default.Z_OK) {
102
+ throw new Error(messages_js_1.message[status]);
103
+ }
104
+ this._dict_set = true;
105
+ }
106
+ }
107
+ push(data, mode) {
108
+ const strm = this.strm;
109
+ const chunkSize = this.options.chunkSize;
110
+ const chunks = [];
111
+ let status;
112
+ if (this.ended) {
113
+ throw new Error("can not call after ended");
114
+ }
115
+ const _mode = mode === ~~mode
116
+ ? mode
117
+ : (mode === true ? status_js_1.default.Z_FINISH : status_js_1.default.Z_NO_FLUSH);
118
+ strm.input = data;
119
+ strm.next_in = 0;
120
+ strm.avail_in = strm.input.length;
121
+ do {
122
+ if (strm.avail_out === 0) {
123
+ strm.output = new Uint8Array(chunkSize);
124
+ strm.next_out = 0;
125
+ strm.avail_out = chunkSize;
126
+ }
127
+ status = zlibDeflate.deflate(strm, _mode); /* no bad return value */
128
+ if (status !== status_js_1.default.Z_STREAM_END && status !== status_js_1.default.Z_OK) {
129
+ this.ended = true;
130
+ throw new Error(this.strm.msg);
131
+ }
132
+ if (strm.avail_out === 0 ||
133
+ (strm.avail_in === 0 &&
134
+ (_mode === status_js_1.default.Z_FINISH || _mode === status_js_1.default.Z_SYNC_FLUSH))) {
135
+ chunks.push(strm.output.subarray(0, strm.next_out));
136
+ }
137
+ } while ((strm.avail_in > 0 || strm.avail_out === 0) &&
138
+ status !== status_js_1.default.Z_STREAM_END);
139
+ // Finalize on the last chunk.
140
+ if (_mode === status_js_1.default.Z_FINISH) {
141
+ status = zlibDeflate.deflateEnd(this.strm);
142
+ this.ended = true;
143
+ if (status !== status_js_1.default.Z_OK)
144
+ throw new Error(this.strm.msg);
145
+ }
146
+ // callback interim results if Z_SYNC_FLUSH.
147
+ if (_mode === status_js_1.default.Z_SYNC_FLUSH) {
148
+ strm.avail_out = 0;
149
+ }
150
+ return (0, uint8_js_1.concatUint8Array)(chunks);
151
+ }
152
+ }
153
+ exports.Deflate = Deflate;
154
+ function deflate(input, options = {}) {
155
+ const deflator = new Deflate(options);
156
+ const result = deflator.push(input, true);
157
+ // That will never happens, if you don't cheat with options :)
158
+ if (deflator.err)
159
+ throw deflator.msg || messages_js_1.message[deflator.err];
160
+ return result;
161
+ }
162
+ exports.deflate = deflate;
163
+ function deflateRaw(input, options = {}) {
164
+ options.raw = true;
165
+ return deflate(input, options);
166
+ }
167
+ exports.deflateRaw = deflateRaw;
168
+ function gzip(input, options = {}) {
169
+ options.gzip = true;
170
+ return deflate(input, options);
171
+ }
172
+ exports.gzip = gzip;
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.gunzip = exports.inflateRaw = exports.inflate = exports.Inflate = void 0;
30
+ // from https://github.com/nodeca/pako
31
+ const uint8_js_1 = require("../utils/uint8.js");
32
+ const zlibInflate = __importStar(require("./zlib/inflate.js"));
33
+ const status_js_1 = __importDefault(require("./zlib/status.js"));
34
+ const messages_js_1 = require("./zlib/messages.js");
35
+ const zstream_js_1 = __importDefault(require("./zlib/zstream.js"));
36
+ const gzheader_js_1 = __importDefault(require("./zlib/gzheader.js"));
37
+ class Inflate {
38
+ constructor(options) {
39
+ Object.defineProperty(this, "err", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: 0
44
+ }); // error code, if happens (0 = Z_OK)
45
+ Object.defineProperty(this, "msg", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: ""
50
+ }); // error message
51
+ Object.defineProperty(this, "ended", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: false
56
+ }); // used to avoid multiple onEnd() calls
57
+ Object.defineProperty(this, "strm", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ Object.defineProperty(this, "options", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ Object.defineProperty(this, "header", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ this.options = {
76
+ chunkSize: 16384,
77
+ windowBits: 0,
78
+ to: "",
79
+ ...options,
80
+ };
81
+ const opt = this.options;
82
+ // Force window size for `raw` data, if not set directly,
83
+ // because we have no header for autodetect.
84
+ if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
85
+ opt.windowBits = -opt.windowBits;
86
+ if (opt.windowBits === 0)
87
+ opt.windowBits = -15;
88
+ }
89
+ // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
90
+ if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
91
+ !(options && options.windowBits)) {
92
+ opt.windowBits += 32;
93
+ }
94
+ // Gzip header has no info about windows size, we can do autodetect only
95
+ // for deflate. So, if window size not set, force it to max when gzip possible
96
+ if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
97
+ // bit 3 (16) -> gzipped data
98
+ // bit 4 (32) -> autodetect gzip/deflate
99
+ if ((opt.windowBits & 15) === 0) {
100
+ opt.windowBits |= 15;
101
+ }
102
+ }
103
+ this.strm = new zstream_js_1.default();
104
+ this.strm.avail_out = 0;
105
+ var status = zlibInflate.inflateInit2(this.strm, opt.windowBits);
106
+ if (status !== status_js_1.default.Z_OK) {
107
+ throw new Error(messages_js_1.message[status]);
108
+ }
109
+ this.header = new gzheader_js_1.default();
110
+ zlibInflate.inflateGetHeader(this.strm, this.header);
111
+ // Setup dictionary
112
+ if (opt.dictionary) {
113
+ if (opt.raw) { //In raw mode we need to set the dictionary early
114
+ status = zlibInflate.inflateSetDictionary(this.strm, opt.dictionary);
115
+ if (status !== status_js_1.default.Z_OK) {
116
+ throw new Error(messages_js_1.message[status]);
117
+ }
118
+ }
119
+ }
120
+ }
121
+ push(data, mode) {
122
+ const strm = this.strm;
123
+ const chunkSize = this.options.chunkSize;
124
+ const dictionary = this.options.dictionary;
125
+ const chunks = [];
126
+ let status;
127
+ // Flag to properly process Z_BUF_ERROR on testing inflate call
128
+ // when we check that all output data was flushed.
129
+ var allowBufError = false;
130
+ if (this.ended) {
131
+ throw new Error("can not call after ended");
132
+ }
133
+ let _mode = (mode === ~~mode)
134
+ ? mode
135
+ : ((mode === true) ? status_js_1.default.Z_FINISH : status_js_1.default.Z_NO_FLUSH);
136
+ strm.input = data;
137
+ strm.next_in = 0;
138
+ strm.avail_in = strm.input.length;
139
+ do {
140
+ if (strm.avail_out === 0) {
141
+ strm.output = new Uint8Array(chunkSize);
142
+ strm.next_out = 0;
143
+ strm.avail_out = chunkSize;
144
+ }
145
+ status = zlibInflate.inflate(strm, status_js_1.default.Z_NO_FLUSH); /* no bad return value */
146
+ if (status === status_js_1.default.Z_NEED_DICT && dictionary) {
147
+ status = zlibInflate.inflateSetDictionary(this.strm, dictionary);
148
+ }
149
+ if (status === status_js_1.default.Z_BUF_ERROR && allowBufError === true) {
150
+ status = status_js_1.default.Z_OK;
151
+ allowBufError = false;
152
+ }
153
+ if (status !== status_js_1.default.Z_STREAM_END && status !== status_js_1.default.Z_OK) {
154
+ this.ended = true;
155
+ throw new Error(this.strm.msg);
156
+ }
157
+ if (strm.next_out) {
158
+ if (strm.avail_out === 0 || status === status_js_1.default.Z_STREAM_END ||
159
+ (strm.avail_in === 0 &&
160
+ (_mode === status_js_1.default.Z_FINISH || _mode === status_js_1.default.Z_SYNC_FLUSH))) {
161
+ chunks.push(strm.output.subarray(0, strm.next_out));
162
+ }
163
+ }
164
+ // When no more input data, we should check that internal inflate buffers
165
+ // are flushed. The only way to do it when avail_out = 0 - run one more
166
+ // inflate pass. But if output data not exists, inflate return Z_BUF_ERROR.
167
+ // Here we set flag to process this error properly.
168
+ //
169
+ // NOTE. Deflate does not return error in this case and does not needs such
170
+ // logic.
171
+ if (strm.avail_in === 0 && strm.avail_out === 0) {
172
+ allowBufError = true;
173
+ }
174
+ } while ((strm.avail_in > 0 || strm.avail_out === 0) &&
175
+ status !== status_js_1.default.Z_STREAM_END);
176
+ if (status === status_js_1.default.Z_STREAM_END) {
177
+ _mode = status_js_1.default.Z_FINISH;
178
+ }
179
+ // Finalize on the last chunk.
180
+ if (_mode === status_js_1.default.Z_FINISH) {
181
+ status = zlibInflate.inflateEnd(this.strm);
182
+ this.ended = true;
183
+ if (status !== status_js_1.default.Z_OK)
184
+ throw new Error(this.strm.msg);
185
+ }
186
+ // callback interim results if Z_SYNC_FLUSH.
187
+ if (_mode === status_js_1.default.Z_SYNC_FLUSH) {
188
+ strm.avail_out = 0;
189
+ }
190
+ return (0, uint8_js_1.concatUint8Array)(chunks);
191
+ }
192
+ }
193
+ exports.Inflate = Inflate;
194
+ function inflate(input, options = {}) {
195
+ const inflator = new Inflate(options);
196
+ const result = inflator.push(input, true);
197
+ // That will never happens, if you don't cheat with options :)
198
+ if (inflator.err)
199
+ throw inflator.msg || messages_js_1.message[inflator.err];
200
+ return result;
201
+ }
202
+ exports.inflate = inflate;
203
+ function inflateRaw(input, options = {}) {
204
+ options.raw = true;
205
+ return inflate(input, options);
206
+ }
207
+ exports.inflateRaw = inflateRaw;
208
+ exports.gunzip = inflate;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./deflate.js"), exports);
18
+ __exportStar(require("./inflate.js"), exports);