@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,55 @@
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 */
30
+
31
+ import { FUNCTION_TYPE, UNDEFINED_TYPE } from "../constants.js";
32
+ import {
33
+ random
34
+ } from "./codecs/sjcl.js";
35
+
36
+ const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != UNDEFINED_TYPE && typeof crypto.getRandomValues == FUNCTION_TYPE;
37
+
38
+ const ERR_INVALID_PASSWORD = "Invalid password";
39
+ const ERR_INVALID_SIGNATURE = "Invalid signature";
40
+ const ERR_ABORT_CHECK_PASSWORD = "zipjs-abort-check-password";
41
+
42
+ export {
43
+ getRandomValues,
44
+ ERR_INVALID_PASSWORD,
45
+ ERR_INVALID_SIGNATURE,
46
+ ERR_ABORT_CHECK_PASSWORD
47
+ };
48
+
49
+ function getRandomValues(array) {
50
+ if (GET_RANDOM_VALUES_SUPPORTED) {
51
+ return crypto.getRandomValues(array);
52
+ } else {
53
+ return random.getRandomValues(array);
54
+ }
55
+ }
@@ -0,0 +1,56 @@
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 TransformStream */
30
+
31
+ import { Crc32 } from "./codecs/crc32.js";
32
+
33
+ class Crc32Stream extends TransformStream {
34
+
35
+ constructor() {
36
+ let stream;
37
+ const crc32 = new Crc32();
38
+ super({
39
+ transform(chunk, controller) {
40
+ crc32.append(chunk);
41
+ controller.enqueue(chunk);
42
+ },
43
+ flush() {
44
+ const value = new Uint8Array(4);
45
+ const dataView = new DataView(value.buffer);
46
+ dataView.setUint32(0, crc32.get());
47
+ stream.value = value;
48
+ }
49
+ });
50
+ stream = this;
51
+ }
52
+ }
53
+
54
+ export {
55
+ Crc32Stream
56
+ };
@@ -0,0 +1,55 @@
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 TransformStream */
30
+
31
+ export {
32
+ StreamAdapter
33
+ };
34
+
35
+ class StreamAdapter {
36
+
37
+ constructor(Codec) {
38
+ return class extends TransformStream {
39
+ constructor(_format, options) {
40
+ const codec = new Codec(options);
41
+ super({
42
+ transform(chunk, controller) {
43
+ controller.enqueue(codec.append(chunk));
44
+ },
45
+ flush(controller) {
46
+ const chunk = codec.flush();
47
+ if (chunk) {
48
+ controller.enqueue(chunk);
49
+ }
50
+ }
51
+ });
52
+ }
53
+ };
54
+ }
55
+ }
@@ -0,0 +1,162 @@
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 TransformStream */
30
+ // deno-lint-ignore-file no-this-alias
31
+
32
+ import { Crc32 } from "./codecs/crc32.js";
33
+ import {
34
+ ERR_INVALID_PASSWORD,
35
+ ERR_ABORT_CHECK_PASSWORD,
36
+ getRandomValues
37
+ } from "./common-crypto.js";
38
+
39
+ const HEADER_LENGTH = 12;
40
+
41
+ class ZipCryptoDecryptionStream extends TransformStream {
42
+
43
+ constructor({ password, passwordVerification, checkPasswordOnly }) {
44
+ super({
45
+ start() {
46
+ Object.assign(this, {
47
+ password,
48
+ passwordVerification
49
+ });
50
+ createKeys(this, password);
51
+ },
52
+ transform(chunk, controller) {
53
+ const zipCrypto = this;
54
+ if (zipCrypto.password) {
55
+ const decryptedHeader = decrypt(zipCrypto, chunk.subarray(0, HEADER_LENGTH));
56
+ zipCrypto.password = null;
57
+ if (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {
58
+ throw new Error(ERR_INVALID_PASSWORD);
59
+ }
60
+ chunk = chunk.subarray(HEADER_LENGTH);
61
+ }
62
+ if (checkPasswordOnly) {
63
+ controller.error(new Error(ERR_ABORT_CHECK_PASSWORD));
64
+ } else {
65
+ controller.enqueue(decrypt(zipCrypto, chunk));
66
+ }
67
+ }
68
+ });
69
+ }
70
+ }
71
+
72
+ class ZipCryptoEncryptionStream extends TransformStream {
73
+
74
+ constructor({ password, passwordVerification }) {
75
+ super({
76
+ start() {
77
+ Object.assign(this, {
78
+ password,
79
+ passwordVerification
80
+ });
81
+ createKeys(this, password);
82
+ },
83
+ transform(chunk, controller) {
84
+ const zipCrypto = this;
85
+ let output;
86
+ let offset;
87
+ if (zipCrypto.password) {
88
+ zipCrypto.password = null;
89
+ const header = getRandomValues(new Uint8Array(HEADER_LENGTH));
90
+ header[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;
91
+ output = new Uint8Array(chunk.length + header.length);
92
+ output.set(encrypt(zipCrypto, header), 0);
93
+ offset = HEADER_LENGTH;
94
+ } else {
95
+ output = new Uint8Array(chunk.length);
96
+ offset = 0;
97
+ }
98
+ output.set(encrypt(zipCrypto, chunk), offset);
99
+ controller.enqueue(output);
100
+ }
101
+ });
102
+ }
103
+ }
104
+
105
+ export {
106
+ ZipCryptoDecryptionStream,
107
+ ZipCryptoEncryptionStream,
108
+ ERR_INVALID_PASSWORD
109
+ };
110
+
111
+ function decrypt(target, input) {
112
+ const output = new Uint8Array(input.length);
113
+ for (let index = 0; index < input.length; index++) {
114
+ output[index] = getByte(target) ^ input[index];
115
+ updateKeys(target, output[index]);
116
+ }
117
+ return output;
118
+ }
119
+
120
+ function encrypt(target, input) {
121
+ const output = new Uint8Array(input.length);
122
+ for (let index = 0; index < input.length; index++) {
123
+ output[index] = getByte(target) ^ input[index];
124
+ updateKeys(target, input[index]);
125
+ }
126
+ return output;
127
+ }
128
+
129
+ function createKeys(target, password) {
130
+ const keys = [0x12345678, 0x23456789, 0x34567890];
131
+ Object.assign(target, {
132
+ keys,
133
+ crcKey0: new Crc32(keys[0]),
134
+ crcKey2: new Crc32(keys[2]),
135
+ });
136
+ for (let index = 0; index < password.length; index++) {
137
+ updateKeys(target, password.charCodeAt(index));
138
+ }
139
+ }
140
+
141
+ function updateKeys(target, byte) {
142
+ let [key0, key1, key2] = target.keys;
143
+ target.crcKey0.append([byte]);
144
+ key0 = ~target.crcKey0.get();
145
+ key1 = getInt32(Math.imul(getInt32(key1 + getInt8(key0)), 134775813) + 1);
146
+ target.crcKey2.append([key1 >>> 24]);
147
+ key2 = ~target.crcKey2.get();
148
+ target.keys = [key0, key1, key2];
149
+ }
150
+
151
+ function getByte(target) {
152
+ const temp = target.keys[2] | 2;
153
+ return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
154
+ }
155
+
156
+ function getInt8(number) {
157
+ return number & 0xFF;
158
+ }
159
+
160
+ function getInt32(number) {
161
+ return number & 0xFFFFFFFF;
162
+ }
@@ -0,0 +1,165 @@
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 TransformStream */
30
+ // deno-lint-ignore-file no-this-alias
31
+
32
+ import { Crc32Stream } from "./crc32-stream.js";
33
+ import {
34
+ AESEncryptionStream,
35
+ AESDecryptionStream
36
+ } from "./aes-crypto-stream.js";
37
+ import {
38
+ ZipCryptoEncryptionStream,
39
+ ZipCryptoDecryptionStream
40
+ } from "./zip-crypto-stream.js";
41
+ import {
42
+ ERR_INVALID_PASSWORD,
43
+ ERR_INVALID_SIGNATURE,
44
+ ERR_ABORT_CHECK_PASSWORD
45
+ } from "./common-crypto.js";
46
+
47
+ const COMPRESSION_FORMAT = "deflate-raw";
48
+
49
+ class DeflateStream extends TransformStream {
50
+
51
+ constructor(options, { chunkSize, CompressionStream, CompressionStreamNative }) {
52
+ super({});
53
+ const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level } = options;
54
+ const stream = this;
55
+ let crc32Stream, encryptionStream;
56
+ let readable = filterEmptyChunks(super.readable);
57
+ if ((!encrypted || zipCrypto) && signed) {
58
+ crc32Stream = new Crc32Stream();
59
+ readable = pipeThrough(readable, crc32Stream);
60
+ }
61
+ if (compressed) {
62
+ readable = pipeThroughCommpressionStream(readable, useCompressionStream, { level, chunkSize }, CompressionStreamNative, CompressionStream);
63
+ }
64
+ if (encrypted) {
65
+ if (zipCrypto) {
66
+ readable = pipeThrough(readable, new ZipCryptoEncryptionStream(options));
67
+ } else {
68
+ encryptionStream = new AESEncryptionStream(options);
69
+ readable = pipeThrough(readable, encryptionStream);
70
+ }
71
+ }
72
+ setReadable(stream, readable, () => {
73
+ let signature;
74
+ if (encrypted && !zipCrypto) {
75
+ signature = encryptionStream.signature;
76
+ }
77
+ if ((!encrypted || zipCrypto) && signed) {
78
+ signature = new DataView(crc32Stream.value.buffer).getUint32(0);
79
+ }
80
+ stream.signature = signature;
81
+ });
82
+ }
83
+ }
84
+
85
+ class InflateStream extends TransformStream {
86
+
87
+ constructor(options, { chunkSize, DecompressionStream, DecompressionStreamNative }) {
88
+ super({});
89
+ const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream } = options;
90
+ let crc32Stream, decryptionStream;
91
+ let readable = filterEmptyChunks(super.readable);
92
+ if (encrypted) {
93
+ if (zipCrypto) {
94
+ readable = pipeThrough(readable, new ZipCryptoDecryptionStream(options));
95
+ } else {
96
+ decryptionStream = new AESDecryptionStream(options);
97
+ readable = pipeThrough(readable, decryptionStream);
98
+ }
99
+ }
100
+ if (compressed) {
101
+ readable = pipeThroughCommpressionStream(readable, useCompressionStream, { chunkSize }, DecompressionStreamNative, DecompressionStream);
102
+ }
103
+ if ((!encrypted || zipCrypto) && signed) {
104
+ crc32Stream = new Crc32Stream();
105
+ readable = pipeThrough(readable, crc32Stream);
106
+ }
107
+ setReadable(this, readable, () => {
108
+ if ((!encrypted || zipCrypto) && signed) {
109
+ const dataViewSignature = new DataView(crc32Stream.value.buffer);
110
+ if (signature != dataViewSignature.getUint32(0, false)) {
111
+ throw new Error(ERR_INVALID_SIGNATURE);
112
+ }
113
+ }
114
+ });
115
+ }
116
+ }
117
+
118
+ export {
119
+ DeflateStream,
120
+ InflateStream,
121
+ ERR_INVALID_PASSWORD,
122
+ ERR_INVALID_SIGNATURE,
123
+ ERR_ABORT_CHECK_PASSWORD
124
+ };
125
+
126
+ function filterEmptyChunks(readable) {
127
+ return pipeThrough(readable, new TransformStream({
128
+ transform(chunk, controller) {
129
+ if (chunk && chunk.length) {
130
+ controller.enqueue(chunk);
131
+ }
132
+ }
133
+ }));
134
+ }
135
+
136
+ function setReadable(stream, readable, flush) {
137
+ readable = pipeThrough(readable, new TransformStream({ flush }));
138
+ Object.defineProperty(stream, "readable", {
139
+ get() {
140
+ return readable;
141
+ }
142
+ });
143
+ }
144
+
145
+ function pipeThroughCommpressionStream(readable, useCompressionStream, options, CodecStreamNative, CodecStream) {
146
+ try {
147
+ const CompressionStream = useCompressionStream && CodecStreamNative ? CodecStreamNative : CodecStream;
148
+ readable = pipeThrough(readable, new CompressionStream(COMPRESSION_FORMAT, options));
149
+ } catch (error) {
150
+ if (useCompressionStream) {
151
+ try {
152
+ readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
153
+ } catch (error) {
154
+ return readable;
155
+ }
156
+ } else {
157
+ return readable;
158
+ }
159
+ }
160
+ return readable;
161
+ }
162
+
163
+ function pipeThrough(readable, transformStream) {
164
+ return readable.pipeThrough(transformStream);
165
+ }
@@ -0,0 +1,48 @@
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 TextDecoder */
30
+
31
+ const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
32
+ const VALID_CP437 = CP437.length == 256;
33
+
34
+ export {
35
+ decodeCP437
36
+ };
37
+
38
+ function decodeCP437(stringValue) {
39
+ if (VALID_CP437) {
40
+ let result = "";
41
+ for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
42
+ result += CP437[stringValue[indexCharacter]];
43
+ }
44
+ return result;
45
+ } else {
46
+ return new TextDecoder().decode(stringValue);
47
+ }
48
+ }
@@ -0,0 +1,43 @@
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 TextDecoder */
30
+
31
+ import { decodeCP437 } from "./cp437-decode.js";
32
+
33
+ export {
34
+ decodeText
35
+ };
36
+
37
+ function decodeText(value, encoding) {
38
+ if (encoding && encoding.trim().toLowerCase() == "cp437") {
39
+ return decodeCP437(value);
40
+ } else {
41
+ return new TextDecoder(encoding).decode(value);
42
+ }
43
+ }
@@ -0,0 +1,38 @@
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 mimeTypes = {};
30
+
31
+ export {
32
+ mimeTypes,
33
+ getMimeType
34
+ };
35
+
36
+ function getMimeType() {
37
+ return "application/octet-stream";
38
+ }
@@ -0,0 +1,48 @@
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 TextEncoder */
30
+
31
+ import { UNDEFINED_TYPE } from "../constants.js";
32
+
33
+ export {
34
+ encodeText
35
+ };
36
+
37
+ function encodeText(value) {
38
+ if (typeof TextEncoder == UNDEFINED_TYPE) {
39
+ value = unescape(encodeURIComponent(value));
40
+ const result = new Uint8Array(value.length);
41
+ for (let i = 0; i < result.length; i++) {
42
+ result[i] = value.charCodeAt(i);
43
+ }
44
+ return result;
45
+ } else {
46
+ return new TextEncoder().encode(value);
47
+ }
48
+ }