@patrickdk77/archive-defuse 0.0.0-stage → 0.1.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 (122) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +378 -2
  3. package/dist/aes7z.d.ts +16 -0
  4. package/dist/aes7z.js +131 -0
  5. package/dist/alone.d.ts +21 -0
  6. package/dist/alone.js +65 -0
  7. package/dist/bcj2.d.ts +21 -0
  8. package/dist/bcj2.js +140 -0
  9. package/dist/bzip2.d.ts +21 -0
  10. package/dist/bzip2.js +688 -0
  11. package/dist/cab.d.ts +63 -0
  12. package/dist/cab.js +493 -0
  13. package/dist/checks.d.ts +23 -0
  14. package/dist/checks.js +123 -0
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.js +364 -0
  17. package/dist/codecs.d.ts +39 -0
  18. package/dist/codecs.js +124 -0
  19. package/dist/coders.d.ts +58 -0
  20. package/dist/coders.js +392 -0
  21. package/dist/crc32.d.ts +8 -0
  22. package/dist/crc32.js +59 -0
  23. package/dist/detect.d.ts +10 -0
  24. package/dist/detect.js +95 -0
  25. package/dist/encoder.d.ts +44 -0
  26. package/dist/encoder.js +114 -0
  27. package/dist/engine.d.ts +44 -0
  28. package/dist/engine.js +753 -0
  29. package/dist/errors.d.ts +64 -0
  30. package/dist/errors.js +98 -0
  31. package/dist/filters.d.ts +34 -0
  32. package/dist/filters.js +385 -0
  33. package/dist/findings.d.ts +26 -0
  34. package/dist/findings.js +176 -0
  35. package/dist/formats.d.ts +24 -0
  36. package/dist/formats.js +106 -0
  37. package/dist/index.d.ts +9 -0
  38. package/dist/index.js +53 -0
  39. package/dist/index.mjs +3 -0
  40. package/dist/inflate64.d.ts +6 -0
  41. package/dist/inflate64.js +388 -0
  42. package/dist/io.d.ts +78 -0
  43. package/dist/io.js +379 -0
  44. package/dist/lzma-formats.d.ts +75 -0
  45. package/dist/lzma-formats.js +373 -0
  46. package/dist/lzma-sniff.d.ts +20 -0
  47. package/dist/lzma-sniff.js +73 -0
  48. package/dist/lzma-writers.d.ts +35 -0
  49. package/dist/lzma-writers.js +276 -0
  50. package/dist/lzma1/LICENSE +201 -0
  51. package/dist/lzma1/NOTICE +36 -0
  52. package/dist/lzma1/crc32.d.ts +4 -0
  53. package/dist/lzma1/crc32.js +19 -0
  54. package/dist/lzma1/hash234.d.ts +22 -0
  55. package/dist/lzma1/hash234.js +75 -0
  56. package/dist/lzma1/hc4.d.ts +30 -0
  57. package/dist/lzma1/hc4.js +142 -0
  58. package/dist/lzma1/header.d.ts +32 -0
  59. package/dist/lzma1/header.js +73 -0
  60. package/dist/lzma1/lz-decoder.d.ts +41 -0
  61. package/dist/lzma1/lz-decoder.js +128 -0
  62. package/dist/lzma1/lz-encoder.d.ts +87 -0
  63. package/dist/lzma1/lz-encoder.js +166 -0
  64. package/dist/lzma1/lzma-coder.d.ts +107 -0
  65. package/dist/lzma1/lzma-coder.js +162 -0
  66. package/dist/lzma1/lzma-decoder.d.ts +36 -0
  67. package/dist/lzma1/lzma-decoder.js +484 -0
  68. package/dist/lzma1/lzma-encoder-fast.d.ts +13 -0
  69. package/dist/lzma1/lzma-encoder-fast.js +114 -0
  70. package/dist/lzma1/lzma-encoder.d.ts +105 -0
  71. package/dist/lzma1/lzma-encoder.js +497 -0
  72. package/dist/lzma1/lzma2-decoder.d.ts +85 -0
  73. package/dist/lzma1/lzma2-decoder.js +249 -0
  74. package/dist/lzma1/range-coder.d.ts +18 -0
  75. package/dist/lzma1/range-coder.js +23 -0
  76. package/dist/lzma1/range-decoder.d.ts +41 -0
  77. package/dist/lzma1/range-decoder.js +78 -0
  78. package/dist/lzma1/range-encoder.d.ts +53 -0
  79. package/dist/lzma1/range-encoder.js +269 -0
  80. package/dist/lzma1-stream.d.ts +60 -0
  81. package/dist/lzma1-stream.js +202 -0
  82. package/dist/model.d.ts +141 -0
  83. package/dist/model.js +16 -0
  84. package/dist/names.d.ts +13 -0
  85. package/dist/names.js +66 -0
  86. package/dist/pack.d.ts +79 -0
  87. package/dist/pack.js +590 -0
  88. package/dist/plugins.d.ts +13 -0
  89. package/dist/plugins.js +56 -0
  90. package/dist/rules.d.ts +25 -0
  91. package/dist/rules.js +403 -0
  92. package/dist/score.d.ts +17 -0
  93. package/dist/score.js +58 -0
  94. package/dist/seven.d.ts +75 -0
  95. package/dist/seven.js +492 -0
  96. package/dist/sevenzip.d.ts +133 -0
  97. package/dist/sevenzip.js +529 -0
  98. package/dist/single.d.ts +103 -0
  99. package/dist/single.js +453 -0
  100. package/dist/sniff.d.ts +20 -0
  101. package/dist/sniff.js +224 -0
  102. package/dist/stream-meter.d.ts +39 -0
  103. package/dist/stream-meter.js +54 -0
  104. package/dist/tar.d.ts +102 -0
  105. package/dist/tar.js +765 -0
  106. package/dist/types.d.ts +311 -0
  107. package/dist/types.js +133 -0
  108. package/dist/unpack.d.ts +67 -0
  109. package/dist/unpack.js +194 -0
  110. package/dist/xz.d.ts +25 -0
  111. package/dist/xz.js +333 -0
  112. package/dist/zip-lzma.d.ts +15 -0
  113. package/dist/zip-lzma.js +137 -0
  114. package/dist/zip-writer.d.ts +51 -0
  115. package/dist/zip-writer.js +305 -0
  116. package/dist/zip.d.ts +99 -0
  117. package/dist/zip.js +901 -0
  118. package/dist/zipcrypt.d.ts +47 -0
  119. package/dist/zipcrypt.js +233 -0
  120. package/dist/zstd.d.ts +25 -0
  121. package/dist/zstd.js +160 -0
  122. package/package.json +94 -4
@@ -0,0 +1,13 @@
1
+ /** Bytes read as code page 437. */
2
+ export declare function cp437(bytes: Uint8Array): string;
3
+ /** Bytes read as UTF-8, or undefined when they are not valid UTF-8. */
4
+ export declare function utf8OrUndefined(bytes: Uint8Array): string | undefined;
5
+ export declare const isAscii: (bytes: Uint8Array) => boolean;
6
+ /** Control characters, and the characters that reorder text, which can make "exe.txt" show as "txt.exe". */
7
+ export declare const CONTROL: RegExp;
8
+ /** `s` without the characters in `chars` at its end. A loop, since a pattern such as /x+$/ backtracks on long runs. */
9
+ export declare function trimEnd(s: string, chars: string): string;
10
+ /** True when a path segment is one Windows cannot create as written. "." and ".." are other rules' business. */
11
+ export declare function windowsReserved(segment: string): boolean;
12
+ /** The segment as Windows can create it: reserved characters and a trailing dot or space become "_", and a device name gets "_" after it. */
13
+ export declare function windowsSafe(segment: string): string;
package/dist/names.js ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONTROL = exports.isAscii = void 0;
4
+ exports.cp437 = cp437;
5
+ exports.utf8OrUndefined = utf8OrUndefined;
6
+ exports.trimEnd = trimEnd;
7
+ exports.windowsReserved = windowsReserved;
8
+ exports.windowsSafe = windowsSafe;
9
+ /** Code page 437, the ZIP format's default for names without the UTF-8 flag: the characters for bytes 0x80 to 0xFF. */
10
+ const CP437_HIGH = [
11
+ 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, 0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9,
12
+ 0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192, 0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb,
13
+ 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, 0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
14
+ 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,
15
+ 0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, 0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248,
16
+ 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0,
17
+ ];
18
+ /** Bytes read as code page 437. */
19
+ function cp437(bytes) {
20
+ let s = '';
21
+ for (const b of bytes)
22
+ s += String.fromCharCode(b < 0x80 ? b : CP437_HIGH[b - 0x80]);
23
+ return s;
24
+ }
25
+ const utf8Strict = new TextDecoder('utf-8', { fatal: true });
26
+ /** Bytes read as UTF-8, or undefined when they are not valid UTF-8. */
27
+ function utf8OrUndefined(bytes) {
28
+ try {
29
+ return utf8Strict.decode(bytes);
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ }
35
+ const isAscii = (bytes) => bytes.every(b => b < 0x80);
36
+ exports.isAscii = isAscii;
37
+ /** Control characters, and the characters that reorder text, which can make "exe.txt" show as "txt.exe". */
38
+ exports.CONTROL = /[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/gu;
39
+ /** Names Windows gives to devices, in any case and with any extension. */
40
+ const RESERVED_DEVICE = /^(con|prn|aux|nul|com[0-9\u00b9\u00b2\u00b3]|lpt[0-9\u00b9\u00b2\u00b3]|conin\$|conout\$)(\..*)?$/i;
41
+ /** Characters Windows does not allow in a name. The colon also opens an alternate data stream on NTFS. */
42
+ const RESERVED_CHARS = /[<>:"|?*]/g;
43
+ /** `s` without the characters in `chars` at its end. A loop, since a pattern such as /x+$/ backtracks on long runs. */
44
+ function trimEnd(s, chars) {
45
+ let end = s.length;
46
+ while (end > 0 && chars.includes(s[end - 1]))
47
+ end--;
48
+ return s.slice(0, end);
49
+ }
50
+ /** True when a path segment is one Windows cannot create as written. "." and ".." are other rules' business. */
51
+ function windowsReserved(segment) {
52
+ if (segment === '.' || segment === '..' || segment === '')
53
+ return false;
54
+ return RESERVED_DEVICE.test(segment) || /[<>:"|?*]/.test(segment) || /[. ]$/.test(segment);
55
+ }
56
+ /** The segment as Windows can create it: reserved characters and a trailing dot or space become "_", and a device name gets "_" after it. */
57
+ function windowsSafe(segment) {
58
+ if (!windowsReserved(segment))
59
+ return segment;
60
+ const replaced = segment.replace(RESERVED_CHARS, '_');
61
+ const kept = trimEnd(replaced, '. ');
62
+ let s = kept + '_'.repeat(replaced.length - kept.length);
63
+ if (RESERVED_DEVICE.test(s))
64
+ s = s.replace(/^([^.]*)/, '$1_');
65
+ return s;
66
+ }
package/dist/pack.d.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { type Readable } from 'node:stream';
2
+ import { type ByteSink } from './types';
3
+ /** What an entry holds: bytes, text written as UTF-8, or a stream such as a Node Readable. */
4
+ export type PackData = Uint8Array | string | AsyncIterable<Uint8Array | string>;
5
+ /** One file, folder or symbolic link to put in an archive. */
6
+ export interface PackEntry {
7
+ /** The path inside the archive, with "/" between folders. A name that ends in "/" is a folder. */
8
+ name: string;
9
+ /** Defaults to 'directory' for a name that ends in "/", 'symlink' when `linkTarget` is set, and 'file' otherwise. */
10
+ kind?: 'file' | 'directory' | 'symlink';
11
+ /**
12
+ * The content of a file, or a function that returns it, which is called when the entry is written. A function lets
13
+ * a caller open a stream only when its turn comes.
14
+ */
15
+ data?: PackData | (() => PackData | Promise<PackData>);
16
+ /** The target of a symbolic link. */
17
+ linkTarget?: string;
18
+ /** Permission bits. Defaults to 0644 for a file and 0755 for a folder. */
19
+ mode?: number;
20
+ /** Defaults to `PackOptions.mtime`. */
21
+ mtime?: Date;
22
+ /** ZIP only: store the file without compression, as the `mimetype` entry of an ODF document needs. */
23
+ store?: boolean;
24
+ }
25
+ /** The archive formats `createArchive` writes. */
26
+ export type PackFormat = 'zip' | 'tar' | 'tar.gz' | 'tar.bz2' | 'tar.zst' | 'tar.xz' | '7z';
27
+ /** The formats that compress one file, which `compress` writes. */
28
+ export type CompressFormat = 'gzip' | 'bzip2' | 'zstd' | 'brotli' | 'xz' | 'lzma';
29
+ export interface PackOptions {
30
+ /**
31
+ * Compression level: 0 to 9 for ZIP deflate and gzip (default 6), 1 to 9 for bzip2 (default 9). The other formats
32
+ * have one level.
33
+ */
34
+ level?: number;
35
+ /** The time of entries that give none. Defaults to the time the call starts. */
36
+ mtime?: Date;
37
+ /** ZIP: the archive's comment. */
38
+ comment?: string;
39
+ /**
40
+ * ZIP and 7z: a file that would compress past this many bytes per compressed byte is stored instead, so the archive
41
+ * reads under the same `limits.compressionRatio` when this package inspects it. Default 1,000, the reading default.
42
+ */
43
+ ratioLimit?: number;
44
+ /** Folder for temporary files. Defaults to `os.tmpdir()`. */
45
+ tempDir?: string;
46
+ /**
47
+ * Bytes of one entry held in memory before a temporary file takes over, default 8 MiB. ZIP, tar and 7z need an
48
+ * entry's size before its data, so an entry given as a stream is read into memory or a temporary file first.
49
+ */
50
+ memoryThreshold?: number;
51
+ /** Stops the work when aborted: the sink is aborted and the call throws the signal's reason. */
52
+ signal?: AbortSignal;
53
+ /**
54
+ * ZIP only: write each file as its data arrives, deflated on the way, with its CRC and sizes in a data descriptor
55
+ * after the data. Nothing goes to a temporary file. An entry with `store: true` is held in memory, since a stored
56
+ * entry keeps its sizes in its header. `ratioLimit` does not apply, since an entry is written before its ratio is
57
+ * known.
58
+ */
59
+ streaming?: boolean;
60
+ }
61
+ /** Thrown for an entry this package will not write, before anything of the entry is written. */
62
+ export declare class PackError extends Error {
63
+ }
64
+ /**
65
+ * Writes an archive of `entries`, in their order, to `sink`, then closes it. Entries can come as a list or as an async
66
+ * iterable, and each file's content as bytes, text or a stream. When anything fails, such as an entry's stream, the
67
+ * sink is aborted instead of closed and the error is thrown.
68
+ */
69
+ export declare function createArchive(format: PackFormat, entries: Iterable<PackEntry> | AsyncIterable<PackEntry>, sink: ByteSink, options?: PackOptions): Promise<void>;
70
+ /** `createArchive` as a Node Readable, to pipe to a file, an HTTP response or an upload. */
71
+ export declare function createArchiveStream(format: PackFormat, entries: Iterable<PackEntry> | AsyncIterable<PackEntry>, options?: PackOptions): Readable;
72
+ /** `createArchive` into memory. */
73
+ export declare function createArchiveBytes(format: PackFormat, entries: Iterable<PackEntry> | AsyncIterable<PackEntry>, options?: PackOptions): Promise<Uint8Array>;
74
+ /** Compresses `data` as one stream of `format` to `sink`, then closes it. */
75
+ export declare function compressTo(format: CompressFormat, data: PackData, sink: ByteSink, options?: PackOptions): Promise<void>;
76
+ /** `compressTo` as a Node Readable. */
77
+ export declare function compressStream(format: CompressFormat, data: PackData, options?: PackOptions): Readable;
78
+ /** `compressTo` into memory. */
79
+ export declare function compress(format: CompressFormat, data: PackData, options?: PackOptions): Promise<Uint8Array>;