@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.
Files changed (110) hide show
  1. package/actions.d.ts +57 -0
  2. package/actions.js +262 -0
  3. package/cli.d.ts +2 -0
  4. package/cli.js +139 -0
  5. package/db.d.ts +110 -0
  6. package/db.js +754 -0
  7. package/downloads.d.ts +2 -0
  8. package/downloads.js +12 -0
  9. package/files.d.ts +56 -0
  10. package/files.js +232 -0
  11. package/index.d.ts +8 -0
  12. package/index.js +38 -0
  13. package/migrations/20240420231455_initial/migration.sql +66 -0
  14. package/migrations/20240623183848_add_book_order/migration.sql +26 -0
  15. package/migrations/20240629194121_add_chapter_links/migration.sql +45 -0
  16. package/migrations/20240629194513_add_chapter_content/migration.sql +30 -0
  17. package/migrations/20240705221833_remove_unused_columns/migration.sql +27 -0
  18. package/migrations/20240711173108_add_chapter_audio/migration.sql +13 -0
  19. package/migrations/20240724212651_add_hashing/migration.sql +25 -0
  20. package/node_modules/@zip.js/zip.js/LICENSE +28 -0
  21. package/node_modules/@zip.js/zip.js/README.md +173 -0
  22. package/node_modules/@zip.js/zip.js/deno.json +8 -0
  23. package/node_modules/@zip.js/zip.js/dist/README.md +28 -0
  24. package/node_modules/@zip.js/zip.js/dist/z-worker-fflate.js +1 -0
  25. package/node_modules/@zip.js/zip.js/dist/z-worker-pako.js +1 -0
  26. package/node_modules/@zip.js/zip.js/dist/z-worker.js +1 -0
  27. package/node_modules/@zip.js/zip.js/dist/zip-fs-full.js +11935 -0
  28. package/node_modules/@zip.js/zip.js/dist/zip-fs-full.min.js +1 -0
  29. package/node_modules/@zip.js/zip.js/dist/zip-fs.js +6079 -0
  30. package/node_modules/@zip.js/zip.js/dist/zip-fs.min.js +1 -0
  31. package/node_modules/@zip.js/zip.js/dist/zip-full.js +9463 -0
  32. package/node_modules/@zip.js/zip.js/dist/zip-full.min.js +1 -0
  33. package/node_modules/@zip.js/zip.js/dist/zip-no-worker-deflate.min.js +1 -0
  34. package/node_modules/@zip.js/zip.js/dist/zip-no-worker-inflate.min.js +1 -0
  35. package/node_modules/@zip.js/zip.js/dist/zip-no-worker.min.js +1 -0
  36. package/node_modules/@zip.js/zip.js/dist/zip.js +5240 -0
  37. package/node_modules/@zip.js/zip.js/dist/zip.min.js +1 -0
  38. package/node_modules/@zip.js/zip.js/index-fflate.js +82 -0
  39. package/node_modules/@zip.js/zip.js/index.cjs +11927 -0
  40. package/node_modules/@zip.js/zip.js/index.d.ts +2048 -0
  41. package/node_modules/@zip.js/zip.js/index.js +87 -0
  42. package/node_modules/@zip.js/zip.js/index.min.js +1 -0
  43. package/node_modules/@zip.js/zip.js/lib/core/codec-pool.js +127 -0
  44. package/node_modules/@zip.js/zip.js/lib/core/codec-worker.js +348 -0
  45. package/node_modules/@zip.js/zip.js/lib/core/configuration.js +127 -0
  46. package/node_modules/@zip.js/zip.js/lib/core/constants.js +114 -0
  47. package/node_modules/@zip.js/zip.js/lib/core/io.js +749 -0
  48. package/node_modules/@zip.js/zip.js/lib/core/streams/aes-crypto-stream.js +326 -0
  49. package/node_modules/@zip.js/zip.js/lib/core/streams/codec-stream.js +154 -0
  50. package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/crc32.js +63 -0
  51. package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/deflate.js +2063 -0
  52. package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/inflate.js +2167 -0
  53. package/node_modules/@zip.js/zip.js/lib/core/streams/codecs/sjcl.js +827 -0
  54. package/node_modules/@zip.js/zip.js/lib/core/streams/common-crypto.js +55 -0
  55. package/node_modules/@zip.js/zip.js/lib/core/streams/crc32-stream.js +56 -0
  56. package/node_modules/@zip.js/zip.js/lib/core/streams/stream-adapter.js +55 -0
  57. package/node_modules/@zip.js/zip.js/lib/core/streams/zip-crypto-stream.js +162 -0
  58. package/node_modules/@zip.js/zip.js/lib/core/streams/zip-entry-stream.js +165 -0
  59. package/node_modules/@zip.js/zip.js/lib/core/util/cp437-decode.js +48 -0
  60. package/node_modules/@zip.js/zip.js/lib/core/util/decode-text.js +43 -0
  61. package/node_modules/@zip.js/zip.js/lib/core/util/default-mime-type.js +38 -0
  62. package/node_modules/@zip.js/zip.js/lib/core/util/encode-text.js +48 -0
  63. package/node_modules/@zip.js/zip.js/lib/core/util/mime-type.js +1639 -0
  64. package/node_modules/@zip.js/zip.js/lib/core/util/stream-codec-shim.js +91 -0
  65. package/node_modules/@zip.js/zip.js/lib/core/z-worker-core.js +176 -0
  66. package/node_modules/@zip.js/zip.js/lib/core/zip-entry.js +86 -0
  67. package/node_modules/@zip.js/zip.js/lib/core/zip-fs-core.js +865 -0
  68. package/node_modules/@zip.js/zip.js/lib/core/zip-reader.js +757 -0
  69. package/node_modules/@zip.js/zip.js/lib/core/zip-writer.js +1186 -0
  70. package/node_modules/@zip.js/zip.js/lib/z-worker-bootstrap-fflate.js +40 -0
  71. package/node_modules/@zip.js/zip.js/lib/z-worker-bootstrap-pako.js +39 -0
  72. package/node_modules/@zip.js/zip.js/lib/z-worker-fflate.js +40 -0
  73. package/node_modules/@zip.js/zip.js/lib/z-worker-inline-template.js +42 -0
  74. package/node_modules/@zip.js/zip.js/lib/z-worker-inline.js +1 -0
  75. package/node_modules/@zip.js/zip.js/lib/z-worker.js +38 -0
  76. package/node_modules/@zip.js/zip.js/lib/zip-data-uri.js +53 -0
  77. package/node_modules/@zip.js/zip.js/lib/zip-fflate-shim.js +37 -0
  78. package/node_modules/@zip.js/zip.js/lib/zip-fs.js +53 -0
  79. package/node_modules/@zip.js/zip.js/lib/zip-full-fflate.js +53 -0
  80. package/node_modules/@zip.js/zip.js/lib/zip-full.js +54 -0
  81. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-deflate.js +42 -0
  82. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate-deflate.js +42 -0
  83. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate-inflate.js +42 -0
  84. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-fflate.js +43 -0
  85. package/node_modules/@zip.js/zip.js/lib/zip-no-worker-inflate.js +42 -0
  86. package/node_modules/@zip.js/zip.js/lib/zip-no-worker.js +44 -0
  87. package/node_modules/@zip.js/zip.js/lib/zip.js +52 -0
  88. package/node_modules/@zip.js/zip.js/package.json +86 -0
  89. package/package.json +43 -0
  90. package/prisma-gen/default.d.ts +1 -0
  91. package/prisma-gen/default.js +1 -0
  92. package/prisma-gen/edge.d.ts +1 -0
  93. package/prisma-gen/edge.js +242 -0
  94. package/prisma-gen/index-browser.js +236 -0
  95. package/prisma-gen/index.d.ts +13248 -0
  96. package/prisma-gen/index.js +265 -0
  97. package/prisma-gen/runtime/edge-esm.js +28 -0
  98. package/prisma-gen/runtime/edge.js +28 -0
  99. package/prisma-gen/runtime/index-browser.d.ts +365 -0
  100. package/prisma-gen/runtime/index-browser.js +13 -0
  101. package/prisma-gen/runtime/library.d.ts +3168 -0
  102. package/prisma-gen/runtime/library.js +140 -0
  103. package/prisma-gen/runtime/wasm.js +29 -0
  104. package/prisma-gen/wasm.d.ts +1 -0
  105. package/prisma-gen/wasm.js +236 -0
  106. package/s3.d.ts +14 -0
  107. package/s3.js +76 -0
  108. package/schema.prisma +154 -0
  109. package/uploads.d.ts +54 -0
  110. package/uploads.js +141 -0
@@ -0,0 +1,326 @@
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
+ /* global crypto, TransformStream */
30
+ // deno-lint-ignore-file no-this-alias
31
+
32
+ import { UNDEFINED_VALUE, UNDEFINED_TYPE, FUNCTION_TYPE } from "../constants.js";
33
+ import { encodeText } from "./../util/encode-text.js";
34
+ import {
35
+ cipher,
36
+ codec,
37
+ misc,
38
+ mode
39
+ } from "./codecs/sjcl.js";
40
+ import {
41
+ ERR_INVALID_PASSWORD,
42
+ ERR_INVALID_SIGNATURE,
43
+ ERR_ABORT_CHECK_PASSWORD,
44
+ getRandomValues
45
+ } from "./common-crypto.js";
46
+
47
+ const BLOCK_LENGTH = 16;
48
+ const RAW_FORMAT = "raw";
49
+ const PBKDF2_ALGORITHM = { name: "PBKDF2" };
50
+ const HASH_ALGORITHM = { name: "HMAC" };
51
+ const HASH_FUNCTION = "SHA-1";
52
+ const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
53
+ const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
54
+ const DERIVED_BITS_USAGE = ["deriveBits"];
55
+ const SALT_LENGTH = [8, 12, 16];
56
+ const KEY_LENGTH = [16, 24, 32];
57
+ const SIGNATURE_LENGTH = 10;
58
+ const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
59
+ // deno-lint-ignore valid-typeof
60
+ const CRYPTO_API_SUPPORTED = typeof crypto != UNDEFINED_TYPE;
61
+ const subtle = CRYPTO_API_SUPPORTED && crypto.subtle;
62
+ const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof subtle != UNDEFINED_TYPE;
63
+ const codecBytes = codec.bytes;
64
+ const Aes = cipher.aes;
65
+ const CtrGladman = mode.ctrGladman;
66
+ const HmacSha1 = misc.hmacSha1;
67
+
68
+ let IMPORT_KEY_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.importKey == FUNCTION_TYPE;
69
+ let DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof subtle.deriveBits == FUNCTION_TYPE;
70
+
71
+ class AESDecryptionStream extends TransformStream {
72
+
73
+ constructor({ password, rawPassword, signed, encryptionStrength, checkPasswordOnly }) {
74
+ super({
75
+ start() {
76
+ Object.assign(this, {
77
+ ready: new Promise(resolve => this.resolveReady = resolve),
78
+ password: encodePassword(password, rawPassword),
79
+ signed,
80
+ strength: encryptionStrength - 1,
81
+ pending: new Uint8Array()
82
+ });
83
+ },
84
+ async transform(chunk, controller) {
85
+ const aesCrypto = this;
86
+ const {
87
+ password,
88
+ strength,
89
+ resolveReady,
90
+ ready
91
+ } = aesCrypto;
92
+ if (password) {
93
+ await createDecryptionKeys(aesCrypto, strength, password, subarray(chunk, 0, SALT_LENGTH[strength] + 2));
94
+ chunk = subarray(chunk, SALT_LENGTH[strength] + 2);
95
+ if (checkPasswordOnly) {
96
+ controller.error(new Error(ERR_ABORT_CHECK_PASSWORD));
97
+ } else {
98
+ resolveReady();
99
+ }
100
+ } else {
101
+ await ready;
102
+ }
103
+ const output = new Uint8Array(chunk.length - SIGNATURE_LENGTH - ((chunk.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
104
+ controller.enqueue(append(aesCrypto, chunk, output, 0, SIGNATURE_LENGTH, true));
105
+ },
106
+ async flush(controller) {
107
+ const {
108
+ signed,
109
+ ctr,
110
+ hmac,
111
+ pending,
112
+ ready
113
+ } = this;
114
+ if (hmac && ctr) {
115
+ await ready;
116
+ const chunkToDecrypt = subarray(pending, 0, pending.length - SIGNATURE_LENGTH);
117
+ const originalSignature = subarray(pending, pending.length - SIGNATURE_LENGTH);
118
+ let decryptedChunkArray = new Uint8Array();
119
+ if (chunkToDecrypt.length) {
120
+ const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
121
+ hmac.update(encryptedChunk);
122
+ const decryptedChunk = ctr.update(encryptedChunk);
123
+ decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
124
+ }
125
+ if (signed) {
126
+ const signature = subarray(fromBits(codecBytes, hmac.digest()), 0, SIGNATURE_LENGTH);
127
+ for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
128
+ if (signature[indexSignature] != originalSignature[indexSignature]) {
129
+ throw new Error(ERR_INVALID_SIGNATURE);
130
+ }
131
+ }
132
+ }
133
+ controller.enqueue(decryptedChunkArray);
134
+ }
135
+ }
136
+ });
137
+ }
138
+ }
139
+
140
+ class AESEncryptionStream extends TransformStream {
141
+
142
+ constructor({ password, rawPassword, encryptionStrength }) {
143
+ // deno-lint-ignore prefer-const
144
+ let stream;
145
+ super({
146
+ start() {
147
+ Object.assign(this, {
148
+ ready: new Promise(resolve => this.resolveReady = resolve),
149
+ password: encodePassword(password, rawPassword),
150
+ strength: encryptionStrength - 1,
151
+ pending: new Uint8Array()
152
+ });
153
+ },
154
+ async transform(chunk, controller) {
155
+ const aesCrypto = this;
156
+ const {
157
+ password,
158
+ strength,
159
+ resolveReady,
160
+ ready
161
+ } = aesCrypto;
162
+ let preamble = new Uint8Array();
163
+ if (password) {
164
+ preamble = await createEncryptionKeys(aesCrypto, strength, password);
165
+ resolveReady();
166
+ } else {
167
+ await ready;
168
+ }
169
+ const output = new Uint8Array(preamble.length + chunk.length - (chunk.length % BLOCK_LENGTH));
170
+ output.set(preamble, 0);
171
+ controller.enqueue(append(aesCrypto, chunk, output, preamble.length, 0));
172
+ },
173
+ async flush(controller) {
174
+ const {
175
+ ctr,
176
+ hmac,
177
+ pending,
178
+ ready
179
+ } = this;
180
+ if (hmac && ctr) {
181
+ await ready;
182
+ let encryptedChunkArray = new Uint8Array();
183
+ if (pending.length) {
184
+ const encryptedChunk = ctr.update(toBits(codecBytes, pending));
185
+ hmac.update(encryptedChunk);
186
+ encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
187
+ }
188
+ stream.signature = fromBits(codecBytes, hmac.digest()).slice(0, SIGNATURE_LENGTH);
189
+ controller.enqueue(concat(encryptedChunkArray, stream.signature));
190
+ }
191
+ }
192
+ });
193
+ stream = this;
194
+ }
195
+ }
196
+
197
+ export {
198
+ AESDecryptionStream,
199
+ AESEncryptionStream,
200
+ ERR_INVALID_PASSWORD
201
+ };
202
+
203
+ function append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {
204
+ const {
205
+ ctr,
206
+ hmac,
207
+ pending
208
+ } = aesCrypto;
209
+ const inputLength = input.length - paddingEnd;
210
+ if (pending.length) {
211
+ input = concat(pending, input);
212
+ output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
213
+ }
214
+ let offset;
215
+ for (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {
216
+ const inputChunk = toBits(codecBytes, subarray(input, offset, offset + BLOCK_LENGTH));
217
+ if (verifySignature) {
218
+ hmac.update(inputChunk);
219
+ }
220
+ const outputChunk = ctr.update(inputChunk);
221
+ if (!verifySignature) {
222
+ hmac.update(outputChunk);
223
+ }
224
+ output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
225
+ }
226
+ aesCrypto.pending = subarray(input, offset);
227
+ return output;
228
+ }
229
+
230
+ async function createDecryptionKeys(decrypt, strength, password, preamble) {
231
+ const passwordVerificationKey = await createKeys(decrypt, strength, password, subarray(preamble, 0, SALT_LENGTH[strength]));
232
+ const passwordVerification = subarray(preamble, SALT_LENGTH[strength]);
233
+ if (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {
234
+ throw new Error(ERR_INVALID_PASSWORD);
235
+ }
236
+ }
237
+
238
+ async function createEncryptionKeys(encrypt, strength, password) {
239
+ const salt = getRandomValues(new Uint8Array(SALT_LENGTH[strength]));
240
+ const passwordVerification = await createKeys(encrypt, strength, password, salt);
241
+ return concat(salt, passwordVerification);
242
+ }
243
+
244
+ async function createKeys(aesCrypto, strength, password, salt) {
245
+ aesCrypto.password = null;
246
+ const baseKey = await importKey(RAW_FORMAT, password, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
247
+ const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), baseKey, 8 * ((KEY_LENGTH[strength] * 2) + 2));
248
+ const compositeKey = new Uint8Array(derivedBits);
249
+ const key = toBits(codecBytes, subarray(compositeKey, 0, KEY_LENGTH[strength]));
250
+ const authentication = toBits(codecBytes, subarray(compositeKey, KEY_LENGTH[strength], KEY_LENGTH[strength] * 2));
251
+ const passwordVerification = subarray(compositeKey, KEY_LENGTH[strength] * 2);
252
+ Object.assign(aesCrypto, {
253
+ keys: {
254
+ key,
255
+ authentication,
256
+ passwordVerification
257
+ },
258
+ ctr: new CtrGladman(new Aes(key), Array.from(COUNTER_DEFAULT_VALUE)),
259
+ hmac: new HmacSha1(authentication)
260
+ });
261
+ return passwordVerification;
262
+ }
263
+
264
+ async function importKey(format, password, algorithm, extractable, keyUsages) {
265
+ if (IMPORT_KEY_SUPPORTED) {
266
+ try {
267
+ return await subtle.importKey(format, password, algorithm, extractable, keyUsages);
268
+ } catch (_error) {
269
+ IMPORT_KEY_SUPPORTED = false;
270
+ return misc.importKey(password);
271
+ }
272
+ } else {
273
+ return misc.importKey(password);
274
+ }
275
+ }
276
+
277
+ async function deriveBits(algorithm, baseKey, length) {
278
+ if (DERIVE_BITS_SUPPORTED) {
279
+ try {
280
+ return await subtle.deriveBits(algorithm, baseKey, length);
281
+ } catch (_error) {
282
+ DERIVE_BITS_SUPPORTED = false;
283
+ return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
284
+ }
285
+ } else {
286
+ return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
287
+ }
288
+ }
289
+
290
+ function encodePassword(password, rawPassword) {
291
+ if (rawPassword === UNDEFINED_VALUE) {
292
+ return encodeText(password);
293
+ } else {
294
+ return rawPassword;
295
+ }
296
+ }
297
+
298
+ function concat(leftArray, rightArray) {
299
+ let array = leftArray;
300
+ if (leftArray.length + rightArray.length) {
301
+ array = new Uint8Array(leftArray.length + rightArray.length);
302
+ array.set(leftArray, 0);
303
+ array.set(rightArray, leftArray.length);
304
+ }
305
+ return array;
306
+ }
307
+
308
+ function expand(inputArray, length) {
309
+ if (length && length > inputArray.length) {
310
+ const array = inputArray;
311
+ inputArray = new Uint8Array(length);
312
+ inputArray.set(array, 0);
313
+ }
314
+ return inputArray;
315
+ }
316
+
317
+ function subarray(array, begin, end) {
318
+ return array.subarray(begin, end);
319
+ }
320
+
321
+ function fromBits(codecBytes, chunk) {
322
+ return codecBytes.fromBits(chunk);
323
+ }
324
+ function toBits(codecBytes, chunk) {
325
+ return codecBytes.toBits(chunk);
326
+ }
@@ -0,0 +1,154 @@
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
+ /* global TransformStream */
37
+ // deno-lint-ignore-file no-this-alias
38
+
39
+ import {
40
+ ERR_INVALID_PASSWORD,
41
+ ERR_INVALID_SIGNATURE,
42
+ ERR_ABORT_CHECK_PASSWORD,
43
+ InflateStream,
44
+ DeflateStream
45
+ } from "./zip-entry-stream.js";
46
+
47
+ const MESSAGE_EVENT_TYPE = "message";
48
+ const MESSAGE_START = "start";
49
+ const MESSAGE_PULL = "pull";
50
+ const MESSAGE_DATA = "data";
51
+ const MESSAGE_ACK_DATA = "ack";
52
+ const MESSAGE_CLOSE = "close";
53
+ const CODEC_DEFLATE = "deflate";
54
+ const CODEC_INFLATE = "inflate";
55
+
56
+ export {
57
+ CODEC_DEFLATE,
58
+ CODEC_INFLATE,
59
+ MESSAGE_EVENT_TYPE,
60
+ MESSAGE_START,
61
+ MESSAGE_PULL,
62
+ MESSAGE_DATA,
63
+ MESSAGE_ACK_DATA,
64
+ MESSAGE_CLOSE,
65
+ ERR_INVALID_PASSWORD,
66
+ ERR_INVALID_SIGNATURE,
67
+ ERR_ABORT_CHECK_PASSWORD,
68
+ CodecStream,
69
+ ChunkStream
70
+ };
71
+
72
+ class CodecStream extends TransformStream {
73
+
74
+ constructor(options, config) {
75
+ super({});
76
+ const codec = this;
77
+ const { codecType } = options;
78
+ let Stream;
79
+ if (codecType.startsWith(CODEC_DEFLATE)) {
80
+ Stream = DeflateStream;
81
+ } else if (codecType.startsWith(CODEC_INFLATE)) {
82
+ Stream = InflateStream;
83
+ }
84
+ let outputSize = 0;
85
+ let inputSize = 0;
86
+ const stream = new Stream(options, config);
87
+ const readable = super.readable;
88
+ const inputSizeStream = new TransformStream({
89
+ transform(chunk, controller) {
90
+ if (chunk && chunk.length) {
91
+ inputSize += chunk.length;
92
+ controller.enqueue(chunk);
93
+ }
94
+ },
95
+ flush() {
96
+ Object.assign(codec, {
97
+ inputSize
98
+ });
99
+ }
100
+ });
101
+ const outputSizeStream = new TransformStream({
102
+ transform(chunk, controller) {
103
+ if (chunk && chunk.length) {
104
+ outputSize += chunk.length;
105
+ controller.enqueue(chunk);
106
+ }
107
+ },
108
+ flush() {
109
+ const { signature } = stream;
110
+ Object.assign(codec, {
111
+ signature,
112
+ outputSize,
113
+ inputSize
114
+ });
115
+ }
116
+ });
117
+ Object.defineProperty(codec, "readable", {
118
+ get() {
119
+ return readable.pipeThrough(inputSizeStream).pipeThrough(stream).pipeThrough(outputSizeStream);
120
+ }
121
+ });
122
+ }
123
+ }
124
+
125
+ class ChunkStream extends TransformStream {
126
+
127
+ constructor(chunkSize) {
128
+ let pendingChunk;
129
+ super({
130
+ transform,
131
+ flush(controller) {
132
+ if (pendingChunk && pendingChunk.length) {
133
+ controller.enqueue(pendingChunk);
134
+ }
135
+ }
136
+ });
137
+
138
+ function transform(chunk, controller) {
139
+ if (pendingChunk) {
140
+ const newChunk = new Uint8Array(pendingChunk.length + chunk.length);
141
+ newChunk.set(pendingChunk);
142
+ newChunk.set(chunk, pendingChunk.length);
143
+ chunk = newChunk;
144
+ pendingChunk = null;
145
+ }
146
+ if (chunk.length > chunkSize) {
147
+ controller.enqueue(chunk.slice(0, chunkSize));
148
+ transform(chunk.slice(chunkSize), controller);
149
+ } else {
150
+ pendingChunk = chunk;
151
+ }
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,63 @@
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
+ const table = [];
30
+ for (let i = 0; i < 256; i++) {
31
+ let t = i;
32
+ for (let j = 0; j < 8; j++) {
33
+ if (t & 1) {
34
+ t = (t >>> 1) ^ 0xEDB88320;
35
+ } else {
36
+ t = t >>> 1;
37
+ }
38
+ }
39
+ table[i] = t;
40
+ }
41
+
42
+ class Crc32 {
43
+
44
+ constructor(crc) {
45
+ this.crc = crc || -1;
46
+ }
47
+
48
+ append(data) {
49
+ let crc = this.crc | 0;
50
+ for (let offset = 0, length = data.length | 0; offset < length; offset++) {
51
+ crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
52
+ }
53
+ this.crc = crc;
54
+ }
55
+
56
+ get() {
57
+ return ~this.crc;
58
+ }
59
+ }
60
+
61
+ export {
62
+ Crc32
63
+ };