@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,107 @@
1
+ /**
2
+ * Probability models and state machine shared by the LZMA encoder and decoder.
3
+ *
4
+ * Ported from XZ for Java (0BSD) by Lasse Collin and Igor Pavlov.
5
+ */
6
+ import { type Probs } from './range-coder';
7
+ export declare const POS_STATES_MAX: number;
8
+ export declare const MATCH_LEN_MIN = 2;
9
+ export declare const LOW_SYMBOLS: number;
10
+ export declare const MID_SYMBOLS: number;
11
+ export declare const HIGH_SYMBOLS: number;
12
+ export declare const MATCH_LEN_MAX: number;
13
+ /**
14
+ * Layout of a length coder, relative to its offset. Lengths 2-9 use a
15
+ * `low` tree, 10-17 a `mid` tree (both per position state), and 18-273 the
16
+ * `high` tree.
17
+ */
18
+ export declare const LEN_CHOICE = 0;
19
+ export declare const LEN_CHOICE2 = 1;
20
+ export declare const LEN_LOW = 2;
21
+ export declare const LEN_MID: number;
22
+ export declare const LEN_HIGH: number;
23
+ export declare const LEN_SIZE: number;
24
+ export declare const DIST_STATES = 4;
25
+ export declare const DIST_SLOT_BITS = 6;
26
+ export declare const DIST_SLOT_COUNT: number;
27
+ export declare const DIST_MODEL_START = 4;
28
+ export declare const DIST_MODEL_END = 14;
29
+ export declare const FULL_DISTANCES: number;
30
+ export declare const ALIGN_BITS = 4;
31
+ export declare const ALIGN_SIZE: number;
32
+ export declare const ALIGN_MASK: number;
33
+ /** Number of recent match distances ("reps") that can be reused cheaply. */
34
+ export declare const REPS = 4;
35
+ /**
36
+ * The coder state remembers the kinds of the most recent symbols
37
+ * (literal, match, long rep, short rep). It selects which probabilities
38
+ * are used for the next symbol.
39
+ */
40
+ export declare const STATES = 12;
41
+ export declare const INITIAL_STATE = 0;
42
+ export declare function isLiteralState(state: number): boolean;
43
+ export declare function stateAfterLiteral(state: number): number;
44
+ export declare function stateAfterMatch(state: number): number;
45
+ export declare function stateAfterLongRep(state: number): number;
46
+ export declare function stateAfterShortRep(state: number): number;
47
+ /** Distances are coded with different probabilities for lengths 2, 3, 4 and 5+. */
48
+ export declare function getDistState(len: number): number;
49
+ /**
50
+ * Layout of the probability array. All probabilities of a coder live in one
51
+ * `Uint16Array`, like in the LZMA SDK and liblzma: one allocation, one reset,
52
+ * and the hot loops index a single array.
53
+ *
54
+ * Bit trees of `2^n` leaves occupy `2^n` entries starting at their offset;
55
+ * index 0 of a tree is unused.
56
+ */
57
+ export declare const IS_MATCH = 0;
58
+ export declare const IS_REP: number;
59
+ export declare const IS_REP0: number;
60
+ export declare const IS_REP1: number;
61
+ export declare const IS_REP2: number;
62
+ export declare const IS_REP0_LONG: number;
63
+ /** Bit trees of 6 bits per distance state. */
64
+ export declare const DIST_SLOTS: number;
65
+ /** Reverse bit trees for the low bits of distances in slots 4-13. */
66
+ export declare const DIST_SPECIAL: number;
67
+ /** Reverse bit tree for the lowest 4 bits of distances in slots 14+. */
68
+ export declare const DIST_ALIGN: number;
69
+ export declare const MATCH_LEN: number;
70
+ export declare const REP_LEN: number;
71
+ /** `2^(lc + lp)` literal coders of 0x300 probabilities each. */
72
+ export declare const LITERAL: number;
73
+ /**
74
+ * Offset of the reverse bit tree for the footer bits of `distSlot` (4-13).
75
+ * The trees are packed like in the LZMA SDK: the tree of a slot starts at
76
+ * `base - distSlot - 1` where `base` is the slot's lowest distance, so the
77
+ * trees of all slots fill `FULL_DISTANCES - DIST_MODEL_END` entries.
78
+ */
79
+ export declare function distSpecialOffset(distSlot: number, base: number): number;
80
+ /** Number of probabilities of a coder with `lc` and `lp` literal bits. */
81
+ export declare function probsSize(lc: number, lp: number): number;
82
+ /**
83
+ * Probability models and coder state shared by the encoder and decoder.
84
+ */
85
+ export declare class LzmaCoder {
86
+ readonly posMask: number;
87
+ private readonly lc;
88
+ private readonly literalPosMask;
89
+ readonly reps: Int32Array<ArrayBuffer>;
90
+ state: number;
91
+ readonly probs: Probs;
92
+ /**
93
+ * @param probs Probability array to reuse, of `probsSize(lc, lp)` entries.
94
+ * Its contents are overwritten by `reset()`.
95
+ */
96
+ constructor(lc: number, lp: number, pb: number, probs?: Probs);
97
+ reset(): void;
98
+ /**
99
+ * Offset of the literal coder for a literal at `pos` after `prevByte`:
100
+ * selected by the high `lc` bits of the previous byte and the low `lp`
101
+ * bits of the position.
102
+ *
103
+ * Each literal coder has 0x300 probabilities: 0x100 for a plain bit
104
+ * tree, and 2 * 0x100 used while the bits still agree with the "match byte".
105
+ */
106
+ literalOffset(prevByte: number, pos: number): number;
107
+ }
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ // Copied from lzma1 (Apache-2.0, Copyright Filip Seman) and changed for lzma-defuse. NOTICE in this folder lists the changes.
3
+ /**
4
+ * Probability models and state machine shared by the LZMA encoder and decoder.
5
+ *
6
+ * Ported from XZ for Java (0BSD) by Lasse Collin and Igor Pavlov.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.LzmaCoder = exports.LITERAL = exports.REP_LEN = exports.MATCH_LEN = exports.DIST_ALIGN = exports.DIST_SPECIAL = exports.DIST_SLOTS = exports.IS_REP0_LONG = exports.IS_REP2 = exports.IS_REP1 = exports.IS_REP0 = exports.IS_REP = exports.IS_MATCH = exports.INITIAL_STATE = exports.STATES = exports.REPS = exports.ALIGN_MASK = exports.ALIGN_SIZE = exports.ALIGN_BITS = exports.FULL_DISTANCES = exports.DIST_MODEL_END = exports.DIST_MODEL_START = exports.DIST_SLOT_COUNT = exports.DIST_SLOT_BITS = exports.DIST_STATES = exports.LEN_SIZE = exports.LEN_HIGH = exports.LEN_MID = exports.LEN_LOW = exports.LEN_CHOICE2 = exports.LEN_CHOICE = exports.MATCH_LEN_MAX = exports.HIGH_SYMBOLS = exports.MID_SYMBOLS = exports.LOW_SYMBOLS = exports.MATCH_LEN_MIN = exports.POS_STATES_MAX = void 0;
10
+ exports.isLiteralState = isLiteralState;
11
+ exports.stateAfterLiteral = stateAfterLiteral;
12
+ exports.stateAfterMatch = stateAfterMatch;
13
+ exports.stateAfterLongRep = stateAfterLongRep;
14
+ exports.stateAfterShortRep = stateAfterShortRep;
15
+ exports.getDistState = getDistState;
16
+ exports.distSpecialOffset = distSpecialOffset;
17
+ exports.probsSize = probsSize;
18
+ const range_coder_1 = require("./range-coder");
19
+ exports.POS_STATES_MAX = 1 << 4;
20
+ exports.MATCH_LEN_MIN = 2;
21
+ exports.LOW_SYMBOLS = 1 << 3;
22
+ exports.MID_SYMBOLS = 1 << 3;
23
+ exports.HIGH_SYMBOLS = 1 << 8;
24
+ exports.MATCH_LEN_MAX = exports.MATCH_LEN_MIN + exports.LOW_SYMBOLS + exports.MID_SYMBOLS + exports.HIGH_SYMBOLS - 1; // 273
25
+ /**
26
+ * Layout of a length coder, relative to its offset. Lengths 2-9 use a
27
+ * `low` tree, 10-17 a `mid` tree (both per position state), and 18-273 the
28
+ * `high` tree.
29
+ */
30
+ exports.LEN_CHOICE = 0;
31
+ exports.LEN_CHOICE2 = 1;
32
+ exports.LEN_LOW = 2; // [posState][LOW_SYMBOLS]
33
+ exports.LEN_MID = exports.LEN_LOW + exports.POS_STATES_MAX * exports.LOW_SYMBOLS; // [posState][MID_SYMBOLS]
34
+ exports.LEN_HIGH = exports.LEN_MID + exports.POS_STATES_MAX * exports.MID_SYMBOLS;
35
+ exports.LEN_SIZE = exports.LEN_HIGH + exports.HIGH_SYMBOLS;
36
+ exports.DIST_STATES = 4;
37
+ exports.DIST_SLOT_BITS = 6;
38
+ exports.DIST_SLOT_COUNT = 1 << exports.DIST_SLOT_BITS;
39
+ exports.DIST_MODEL_START = 4;
40
+ exports.DIST_MODEL_END = 14;
41
+ exports.FULL_DISTANCES = 1 << (exports.DIST_MODEL_END / 2);
42
+ exports.ALIGN_BITS = 4;
43
+ exports.ALIGN_SIZE = 1 << exports.ALIGN_BITS;
44
+ exports.ALIGN_MASK = exports.ALIGN_SIZE - 1;
45
+ /** Number of recent match distances ("reps") that can be reused cheaply. */
46
+ exports.REPS = 4;
47
+ /**
48
+ * The coder state remembers the kinds of the most recent symbols
49
+ * (literal, match, long rep, short rep). It selects which probabilities
50
+ * are used for the next symbol.
51
+ */
52
+ exports.STATES = 12;
53
+ /** States below this value mean the previous symbol was a literal. */
54
+ const LIT_STATES = 7;
55
+ const LIT_LIT = 0;
56
+ const SHORTREP_LIT_LIT = 3;
57
+ const LIT_MATCH = 7;
58
+ const LIT_LONGREP = 8;
59
+ const LIT_SHORTREP = 9;
60
+ const NONLIT_MATCH = 10;
61
+ const NONLIT_REP = 11;
62
+ exports.INITIAL_STATE = LIT_LIT;
63
+ function isLiteralState(state) {
64
+ return state < LIT_STATES;
65
+ }
66
+ function stateAfterLiteral(state) {
67
+ if (state <= SHORTREP_LIT_LIT)
68
+ return LIT_LIT;
69
+ if (state <= LIT_SHORTREP)
70
+ return state - 3;
71
+ return state - 6;
72
+ }
73
+ function stateAfterMatch(state) {
74
+ return state < LIT_STATES ? LIT_MATCH : NONLIT_MATCH;
75
+ }
76
+ function stateAfterLongRep(state) {
77
+ return state < LIT_STATES ? LIT_LONGREP : NONLIT_REP;
78
+ }
79
+ function stateAfterShortRep(state) {
80
+ return state < LIT_STATES ? LIT_SHORTREP : NONLIT_REP;
81
+ }
82
+ /** Distances are coded with different probabilities for lengths 2, 3, 4 and 5+. */
83
+ function getDistState(len) {
84
+ return len < exports.DIST_STATES + exports.MATCH_LEN_MIN ? len - exports.MATCH_LEN_MIN : exports.DIST_STATES - 1;
85
+ }
86
+ /**
87
+ * Layout of the probability array. All probabilities of a coder live in one
88
+ * `Uint16Array`, like in the LZMA SDK and liblzma: one allocation, one reset,
89
+ * and the hot loops index a single array.
90
+ *
91
+ * Bit trees of `2^n` leaves occupy `2^n` entries starting at their offset;
92
+ * index 0 of a tree is unused.
93
+ */
94
+ exports.IS_MATCH = 0; // [state][posState]
95
+ exports.IS_REP = exports.IS_MATCH + exports.STATES * exports.POS_STATES_MAX; // [state]
96
+ exports.IS_REP0 = exports.IS_REP + exports.STATES; // [state]
97
+ exports.IS_REP1 = exports.IS_REP0 + exports.STATES; // [state]
98
+ exports.IS_REP2 = exports.IS_REP1 + exports.STATES; // [state]
99
+ exports.IS_REP0_LONG = exports.IS_REP2 + exports.STATES; // [state][posState]
100
+ /** Bit trees of 6 bits per distance state. */
101
+ exports.DIST_SLOTS = exports.IS_REP0_LONG + exports.STATES * exports.POS_STATES_MAX;
102
+ /** Reverse bit trees for the low bits of distances in slots 4-13. */
103
+ exports.DIST_SPECIAL = exports.DIST_SLOTS + exports.DIST_STATES * exports.DIST_SLOT_COUNT;
104
+ /** Reverse bit tree for the lowest 4 bits of distances in slots 14+. */
105
+ exports.DIST_ALIGN = exports.DIST_SPECIAL + exports.FULL_DISTANCES - exports.DIST_MODEL_END;
106
+ exports.MATCH_LEN = exports.DIST_ALIGN + exports.ALIGN_SIZE;
107
+ exports.REP_LEN = exports.MATCH_LEN + exports.LEN_SIZE;
108
+ /** `2^(lc + lp)` literal coders of 0x300 probabilities each. */
109
+ exports.LITERAL = exports.REP_LEN + exports.LEN_SIZE;
110
+ /**
111
+ * Offset of the reverse bit tree for the footer bits of `distSlot` (4-13).
112
+ * The trees are packed like in the LZMA SDK: the tree of a slot starts at
113
+ * `base - distSlot - 1` where `base` is the slot's lowest distance, so the
114
+ * trees of all slots fill `FULL_DISTANCES - DIST_MODEL_END` entries.
115
+ */
116
+ function distSpecialOffset(distSlot, base) {
117
+ return exports.DIST_SPECIAL + base - distSlot - 1;
118
+ }
119
+ /** Number of probabilities of a coder with `lc` and `lp` literal bits. */
120
+ function probsSize(lc, lp) {
121
+ return exports.LITERAL + (0x300 << (lc + lp));
122
+ }
123
+ /**
124
+ * Probability models and coder state shared by the encoder and decoder.
125
+ */
126
+ class LzmaCoder {
127
+ posMask;
128
+ lc;
129
+ literalPosMask;
130
+ reps = new Int32Array(exports.REPS);
131
+ state = exports.INITIAL_STATE;
132
+ probs;
133
+ /**
134
+ * @param probs Probability array to reuse, of `probsSize(lc, lp)` entries.
135
+ * Its contents are overwritten by `reset()`.
136
+ */
137
+ constructor(lc, lp, pb, probs) {
138
+ this.posMask = (1 << pb) - 1;
139
+ this.lc = lc;
140
+ this.literalPosMask = (1 << lp) - 1;
141
+ this.probs = probs ?? new Uint16Array(probsSize(lc, lp));
142
+ }
143
+ reset() {
144
+ this.reps.fill(0);
145
+ this.state = exports.INITIAL_STATE;
146
+ (0, range_coder_1.initProbs)(this.probs);
147
+ }
148
+ /**
149
+ * Offset of the literal coder for a literal at `pos` after `prevByte`:
150
+ * selected by the high `lc` bits of the previous byte and the low `lp`
151
+ * bits of the position.
152
+ *
153
+ * Each literal coder has 0x300 probabilities: 0x100 for a plain bit
154
+ * tree, and 2 * 0x100 used while the bits still agree with the "match byte".
155
+ */
156
+ literalOffset(prevByte, pos) {
157
+ const low = prevByte >> (8 - this.lc);
158
+ const high = (pos & this.literalPosMask) << this.lc;
159
+ return exports.LITERAL + 0x300 * (low + high);
160
+ }
161
+ }
162
+ exports.LzmaCoder = LzmaCoder;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * LZMA decoder: turns range-coded symbols back into literals and matches.
3
+ *
4
+ * Ported from XZ for Java (0BSD) by Lasse Collin and Igor Pavlov. The main
5
+ * loop is structured like `LzmaDec_DecodeReal` of the LZMA SDK.
6
+ */
7
+ import type { LzDecoder } from './lz-decoder';
8
+ import { LzmaCoder } from './lzma-coder';
9
+ import type { RangeDecoder } from './range-decoder';
10
+ export declare class LzmaDecoder extends LzmaCoder {
11
+ private readonly lz;
12
+ private readonly rc;
13
+ /** Number of bytes decoded so far. */
14
+ outPos: number;
15
+ constructor(lz: LzDecoder, rc: RangeDecoder, lc: number, lp: number, pb: number, probs?: Uint16Array);
16
+ /**
17
+ * Decodes symbols until `outLimit` bytes have been produced or the input
18
+ * position passes `inLimit`.
19
+ *
20
+ * Performance: this is the hot loop of decompression. The range decoder
21
+ * state, the coder state and the reps live in local variables, and the
22
+ * bit decoding step (`decodeBit` in `range-coder_test.ts`) is repeated inline:
23
+ *
24
+ * prob = probs[i];
25
+ * bound = (range >>> 11) * prob;
26
+ * if (code < bound) { range = bound; probs[i] = prob + ((2048 - prob) >>> 5); bit 0 }
27
+ * else { range -= bound; code -= bound; probs[i] = prob - (prob >>> 5); bit 1 }
28
+ * if (range < 2^24) { shift in the next input byte }
29
+ *
30
+ * With the state in object fields, engines store and reload it around
31
+ * every probability update, which costs 10-15% on V8.
32
+ *
33
+ * @returns `true` if the end marker was decoded
34
+ */
35
+ decode(outLimit: number, inLimit: number): boolean;
36
+ }