@mtkruto/browser 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 +58 -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 +89 -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 +238 -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 +36 -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 +6 -0
  55. package/esm/utilities/1_auth.js +28 -0
  56. package/esm/utilities/1_message.js +94 -0
  57. package/esm/utilities/1_obfuscation.js +32 -0
  58. package/package.json +29 -0
  59. package/script/_dnt.shims.js +61 -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 +93 -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 +247 -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 +43 -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 +11 -0
  111. package/script/utilities/1_auth.js +32 -0
  112. package/script/utilities/1_message.js +102 -0
  113. package/script/utilities/1_obfuscation.js +36 -0
  114. package/types/_dnt.shims.d.ts +1 -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,247 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkTail = exports.checkHeader = exports.gunzip = exports.gzip = exports.getHeader = exports.putLong = exports.DEFAULT_LEVEL = void 0;
4
+ const mod_js_1 = require("../../../../../deno.land/x/crc32@v0.2.0/mod.js");
5
+ /** very fast */
6
+ const mod_js_2 = require("../zlib/mod.js");
7
+ /** slow */
8
+ // import { deflateRaw, inflateRaw } from "../deflate/mod.ts";
9
+ // magic numbers marking this file as GZIP
10
+ const ID1 = 0x1F;
11
+ const ID2 = 0x8B;
12
+ const compressionMethods = {
13
+ "deflate": 8,
14
+ };
15
+ const possibleFlags = {
16
+ "FTEXT": 0x01,
17
+ "FHCRC": 0x02,
18
+ "FEXTRA": 0x04,
19
+ "FNAME": 0x08,
20
+ "FCOMMENT": 0x10,
21
+ };
22
+ // const osMap = {
23
+ // "fat": 0, // FAT file system (DOS, OS/2, NT) + PKZIPW 2.50 VFAT, NTFS
24
+ // "amiga": 1, // Amiga
25
+ // "vmz": 2, // VMS (VAX or Alpha AXP)
26
+ // "unix": 3, // Unix
27
+ // "vm/cms": 4, // VM/CMS
28
+ // "atari": 5, // Atari
29
+ // "hpfs": 6, // HPFS file system (OS/2, NT 3.x)
30
+ // "macintosh": 7, // Macintosh
31
+ // "z-system": 8, // Z-System
32
+ // "cplm": 9, // CP/M
33
+ // "tops-20": 10, // TOPS-20
34
+ // "ntfs": 11, // NTFS file system (NT)
35
+ // "qdos": 12, // SMS/QDOS
36
+ // "acorn": 13, // Acorn RISC OS
37
+ // "vfat": 14, // VFAT file system (Win95, NT)
38
+ // "vms": 15, // MVS (code also taken for PRIMOS)
39
+ // "beos": 16, // BeOS (BeBox or PowerMac)
40
+ // "tandem": 17, // Tandem/NSK
41
+ // "theos": 18, // THEOS
42
+ // };
43
+ const os = {
44
+ "darwin": 3,
45
+ "linux": 3,
46
+ "windows": 0,
47
+ };
48
+ // @ts-ignore
49
+ const osCode = os[globalThis["Deno"]?.build?.os] ?? 255;
50
+ exports.DEFAULT_LEVEL = 6;
51
+ function putByte(n, arr) {
52
+ arr.push(n & 0xFF);
53
+ }
54
+ // LSB first
55
+ function putShort(n, arr) {
56
+ arr.push(n & 0xFF);
57
+ arr.push(n >>> 8);
58
+ }
59
+ // LSB first
60
+ function putLong(n, arr) {
61
+ putShort(n & 0xffff, arr);
62
+ putShort(n >>> 16, arr);
63
+ }
64
+ exports.putLong = putLong;
65
+ function putString(s, arr) {
66
+ for (let i = 0, len = s.length; i < len; i += 1) {
67
+ putByte(s.charCodeAt(i), arr);
68
+ }
69
+ }
70
+ function readByte(arr) {
71
+ return arr.shift();
72
+ }
73
+ function readShort(arr) {
74
+ return arr.shift() | (arr.shift() << 8);
75
+ }
76
+ function readLong(arr) {
77
+ const n1 = readShort(arr);
78
+ let n2 = readShort(arr);
79
+ // JavaScript can't handle bits in the position 32
80
+ // we'll emulate this by removing the left-most bit (if it exists)
81
+ // and add it back in via multiplication, which does work
82
+ if (n2 > 32768) {
83
+ n2 -= 32768;
84
+ return ((n2 << 16) | n1) + 32768 * Math.pow(2, 16);
85
+ }
86
+ return (n2 << 16) | n1;
87
+ }
88
+ function readString(arr) {
89
+ const charArr = [];
90
+ // turn all bytes into chars until the terminating null
91
+ while (arr[0] !== 0) {
92
+ charArr.push(String.fromCharCode(arr.shift()));
93
+ }
94
+ // throw away terminating null
95
+ arr.shift();
96
+ // join all characters into a cohesive string
97
+ return charArr.join("");
98
+ }
99
+ function readBytes(arr, n) {
100
+ const ret = [];
101
+ for (let i = 0; i < n; i += 1) {
102
+ ret.push(arr.shift());
103
+ }
104
+ return ret;
105
+ }
106
+ function getHeader(options = {}) {
107
+ let flags = 0;
108
+ const level = options.level ?? exports.DEFAULT_LEVEL;
109
+ const out = [];
110
+ putByte(ID1, out);
111
+ putByte(ID2, out);
112
+ putByte(compressionMethods["deflate"], out);
113
+ if (options.name) {
114
+ flags |= possibleFlags["FNAME"];
115
+ }
116
+ putByte(flags, out);
117
+ putLong(options.timestamp ?? Math.floor(Date.now() / 1000), out);
118
+ // put deflate args (extra flags)
119
+ if (level === 1) {
120
+ // fastest algorithm
121
+ putByte(4, out);
122
+ }
123
+ else if (level === 9) {
124
+ // maximum compression (fastest algorithm)
125
+ putByte(2, out);
126
+ }
127
+ else {
128
+ putByte(0, out);
129
+ }
130
+ // OS identifier
131
+ putByte(osCode, out);
132
+ if (options.name) {
133
+ // ignore the directory part
134
+ putString(options.name.substring(options.name.lastIndexOf("/") + 1), out);
135
+ // terminating null
136
+ putByte(0, out);
137
+ }
138
+ return new Uint8Array(out);
139
+ }
140
+ exports.getHeader = getHeader;
141
+ function gzip(bytes, options = {}) {
142
+ let flags = 0;
143
+ const level = options.level ?? exports.DEFAULT_LEVEL;
144
+ const out = [];
145
+ putByte(ID1, out);
146
+ putByte(ID2, out);
147
+ putByte(compressionMethods["deflate"], out);
148
+ if (options.name) {
149
+ flags |= possibleFlags["FNAME"];
150
+ }
151
+ putByte(flags, out);
152
+ putLong(options.timestamp ?? Math.floor(Date.now() / 1000), out);
153
+ // put deflate args (extra flags)
154
+ if (level === 1) {
155
+ // fastest algorithm
156
+ putByte(4, out);
157
+ }
158
+ else if (level === 9) {
159
+ // maximum compression (fastest algorithm)
160
+ putByte(2, out);
161
+ }
162
+ else {
163
+ putByte(0, out);
164
+ }
165
+ // OS identifier
166
+ putByte(osCode, out);
167
+ if (options.name) {
168
+ // ignore the directory part
169
+ putString(options.name.substring(options.name.lastIndexOf("/") + 1), out);
170
+ // terminating null
171
+ putByte(0, out);
172
+ }
173
+ (0, mod_js_2.deflateRaw)(bytes).forEach(function (byte) {
174
+ putByte(byte, out);
175
+ });
176
+ // import { deflateRaw, inflateRaw } from "../deflate/mod.ts";
177
+ // deflateRaw(bytes, level).forEach(function (byte) {
178
+ // putByte(byte, out);
179
+ // });
180
+ putLong(parseInt((0, mod_js_1.crc32)(bytes), 16), out);
181
+ putLong(bytes.length, out);
182
+ return new Uint8Array(out);
183
+ }
184
+ exports.gzip = gzip;
185
+ function gunzip(bytes) {
186
+ const arr = Array.from(bytes);
187
+ checkHeader(arr);
188
+ // give deflate everything but the last 8 bytes
189
+ // the last 8 bytes are for the CRC32 checksum and filesize
190
+ const res = (0, mod_js_2.inflateRaw)(new Uint8Array(arr.splice(0, arr.length - 8)));
191
+ // if (flags & possibleFlags["FTEXT"]) {
192
+ // res = Array.prototype.map.call(res, function (byte) {
193
+ // return String.fromCharCode(byte);
194
+ // }).join("");
195
+ // }
196
+ const crc = readLong(arr) >>> 0;
197
+ if (crc !== parseInt((0, mod_js_1.crc32)(res), 16)) {
198
+ throw "Checksum does not match";
199
+ }
200
+ const size = readLong(arr);
201
+ if (size !== res.length) {
202
+ throw "Size of decompressed file not correct";
203
+ }
204
+ return res;
205
+ }
206
+ exports.gunzip = gunzip;
207
+ function checkHeader(arr) {
208
+ // check the first two bytes for the magic numbers
209
+ if (readByte(arr) !== ID1 || readByte(arr) !== ID2) {
210
+ throw "Not a GZIP file";
211
+ }
212
+ if (readByte(arr) !== 8) {
213
+ throw "Unsupported compression method";
214
+ }
215
+ const flags = readByte(arr);
216
+ readLong(arr); // mtime
217
+ readByte(arr); // xFlags
218
+ readByte(arr); // os, throw away
219
+ // just throw away the bytes for now
220
+ if (flags & possibleFlags["FEXTRA"]) {
221
+ const t = readShort(arr);
222
+ readBytes(arr, t);
223
+ }
224
+ // just throw away for now
225
+ if (flags & possibleFlags["FNAME"]) {
226
+ readString(arr);
227
+ }
228
+ // just throw away for now
229
+ if (flags & possibleFlags["FCOMMENT"]) {
230
+ readString(arr);
231
+ }
232
+ // just throw away for now
233
+ if (flags & possibleFlags["FHCRC"]) {
234
+ readShort(arr);
235
+ }
236
+ }
237
+ exports.checkHeader = checkHeader;
238
+ function checkTail(arr) {
239
+ const tail = arr.splice(arr.length - 8);
240
+ const crc32 = readLong(tail) >>> 0;
241
+ const size = readLong(tail);
242
+ return {
243
+ crc32,
244
+ size,
245
+ };
246
+ }
247
+ 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);
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function adler32(adler, buf, len, pos) {
4
+ let s1 = (adler & 0xffff) | 0;
5
+ let s2 = ((adler >>> 16) & 0xffff) | 0;
6
+ let n = 0;
7
+ while (len !== 0) {
8
+ // Set limit ~ twice less than 5552, to keep
9
+ // s2 in 31-bits, because we force signed ints.
10
+ // in other case %= will fail.
11
+ n = len > 2000 ? 2000 : len;
12
+ len -= n;
13
+ do {
14
+ s1 = (s1 + buf[pos++]) | 0;
15
+ s2 = (s2 + s1) | 0;
16
+ } while (--n);
17
+ s1 %= 65521;
18
+ s2 %= 65521;
19
+ }
20
+ return (s1 | (s2 << 16)) | 0;
21
+ }
22
+ exports.default = adler32;