@patrickdk77/archive-defuse 0.1.1 → 0.1.3

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.
@@ -6,13 +6,21 @@
6
6
  * - `LzmaEncoderFast` uses simple heuristics (levels 1-3).
7
7
  * - `LzmaEncoderNormal` searches for the cheapest symbol sequence (levels 4-9).
8
8
  *
9
- * Ported from XZ for Java (0BSD) by Lasse Collin and Igor Pavlov.
9
+ * Ported from XZ for Java (0BSD), `src/org/tukaani/xz/lzma/LZMAEncoder.java`,
10
+ * by Lasse Collin and Igor Pavlov. The LZMA2 entry points and chunk limits
11
+ * are not ported; this library produces only LZMA1 (".lzma") streams. The
12
+ * inner coder classes take their outer encoder (or the range encoder) as
13
+ * an explicit parameter where Java captures it implicitly.
10
14
  */
11
15
  import type { LzEncoder, Matches } from './lz-encoder';
12
- import { LzmaCoder } from './lzma-coder';
16
+ import { LengthCoder, LiteralCoder, LzmaCoder } from './lzma-coder';
13
17
  import { type Probs } from './range-coder';
14
18
  import { type RangeEncoder } from './range-encoder';
15
- /** Returns the distance slot: roughly 2 * log2(dist), plus the next bit. */
19
+ /**
20
+ * Gets an integer [0, 63] matching the highest two bits of an integer.
21
+ * This is like bit scan reverse (BSR) on x86 except that this also
22
+ * cares about the second highest bit.
23
+ */
16
24
  export declare function getDistSlot(dist: number): number;
17
25
  export interface LzmaEncoderConfig {
18
26
  lc: number;
@@ -24,18 +32,18 @@ export interface LzmaEncoderConfig {
24
32
  export declare abstract class LzmaEncoder extends LzmaCoder {
25
33
  private rc;
26
34
  readonly lz: LzEncoder;
27
- readonly niceLen: number;
35
+ readonly literalEncoder: LiteralEncoder;
28
36
  readonly matchLenEncoder: LengthEncoder;
29
37
  readonly repLenEncoder: LengthEncoder;
38
+ readonly niceLen: number;
30
39
  private distPriceCount;
31
40
  private alignPriceCount;
32
- /** Whether a distance or align bits were encoded since the last reset. */
41
+ /** Whether a distance was encoded since the last reset. */
33
42
  private distModelsUsed;
43
+ /** Whether align bits were encoded since the last reset. */
34
44
  private alignModelUsed;
35
45
  private readonly distSlotPricesSize;
36
- /** Price of each distance slot per distance state, `[distState << 6 | slot]`. */
37
46
  private readonly distSlotPrices;
38
- /** Price of each distance below `FULL_DISTANCES` per distance state, `[distState << 7 | dist]`. */
39
47
  private readonly fullDistPrices;
40
48
  private readonly alignPrices;
41
49
  /**
@@ -43,63 +51,83 @@ export declare abstract class LzmaEncoder extends LzmaCoder {
43
51
  * -1 = literal, 0-3 = rep match, 4+ = match with distance `back - REPS`.
44
52
  */
45
53
  protected back: number;
46
- /** Bytes the match finder is ahead of the encoder. */
47
- protected readAhead: number;
54
+ /** Bytes the match finder is ahead of the encoder. Package-private in Java. */
55
+ readAhead: number;
48
56
  constructor(rc: RangeEncoder, lz: LzEncoder, config: LzmaEncoderConfig);
49
- /** Prepares for a new, independent input written to `rc`. */
57
+ /**
58
+ * Prepares for a new, independent input written to `rc` (contract
59
+ * adaptation: lets a pooled encoder be reused by a later call).
60
+ */
50
61
  restart(rc: RangeEncoder): void;
51
62
  /**
52
- * Chooses the next symbol: sets `back` and returns its length.
63
+ * Gets the next LZMA symbol.
64
+ *
65
+ * There are three types of symbols: literal (a single byte),
66
+ * repeated match, and normal match. The symbol is indicated
67
+ * by the return value and by the variable `back`.
68
+ *
69
+ * Literal: `back == -1` and return value is `1`.
70
+ * The literal itself needs to be read from `lz` separately.
71
+ *
72
+ * Repeated match: `back` is in the range [0, 3] and
73
+ * the return value is the length of the repeated match.
74
+ *
75
+ * Normal match: `back - REPS` (`back - 4`)
76
+ * is the distance of the match and the return value is the length
77
+ * of the match.
53
78
  */
54
79
  protected abstract getNextSymbol(): number;
55
80
  reset(): void;
56
- /** Encodes as much of the buffered input as the lookahead allows. */
81
+ /** Compress for LZMA1. */
57
82
  encode(): void;
58
- /** Encodes the end marker: a match with distance 0xFFFFFFFF. */
59
83
  encodeEndMarker(): void;
60
- /** The first symbol is always a literal with no previous byte. */
61
84
  private encodeInit;
62
85
  private encodeSymbol;
63
- private encodeLiteral;
64
86
  private encodeMatch;
65
87
  private encodeRepMatch;
66
88
  protected getMatches(): Matches;
67
89
  protected skip(len: number): void;
68
- protected getLiteralPrice(curByte: number, matchByte: number, prevByte: number, pos: number, state: number): number;
69
- protected getAnyMatchPrice(state: number, posState: number): number;
70
- protected getNormalMatchPrice(anyMatchPrice: number, state: number): number;
71
- protected getAnyRepPrice(anyMatchPrice: number, state: number): number;
72
- protected getShortRepPrice(anyRepPrice: number, state: number, posState: number): number;
73
- protected getLongRepPrice(anyRepPrice: number, rep: number, state: number, posState: number): number;
74
- protected getLongRepAndLenPrice(rep: number, len: number, state: number, posState: number): number;
75
- protected getMatchAndLenPrice(normalMatchPrice: number, dist: number, len: number, posState: number): number;
76
- /** Price of coding `dist` in distance state `distState`. */
77
- protected getDistPrice(distState: number, dist: number): number;
78
- /** Refreshes the price tables that are due for an update. */
79
- protected updatePrices(): void;
90
+ getAnyMatchPrice(state: number, posState: number): number;
91
+ getNormalMatchPrice(anyMatchPrice: number, state: number): number;
92
+ getAnyRepPrice(anyMatchPrice: number, state: number): number;
93
+ getShortRepPrice(anyRepPrice: number, state: number, posState: number): number;
94
+ getLongRepPrice(anyRepPrice: number, rep: number, state: number, posState: number): number;
95
+ getLongRepAndLenPrice(rep: number, len: number, state: number, posState: number): number;
96
+ getDistPrice(distState: number, dist: number): number;
97
+ getMatchAndLenPrice(normalMatchPrice: number, dist: number, len: number, posState: number): number;
80
98
  private updateDistPrices;
81
99
  private updateAlignPrices;
100
+ /**
101
+ * Updates the lookup tables used for calculating match distance
102
+ * and length prices. The updating is skipped for performance reasons
103
+ * if the tables haven't changed much since the previous update.
104
+ */
105
+ updatePrices(): void;
82
106
  }
83
- /**
84
- * Length encoder with cached prices. Prices of each position state are
85
- * recalculated after every `LEN_PRICE_UPDATE_INTERVAL` encoded lengths.
86
- */
87
- export declare class LengthEncoder {
88
- private readonly probs;
89
- /** Offset of this length coder in `probs`. */
90
- private readonly coder;
107
+ export declare class LiteralEncoder extends LiteralCoder {
108
+ private readonly encoder;
109
+ private readonly subencoders;
110
+ constructor(encoder: LzmaEncoder, lc: number, lp: number);
111
+ encodeInit(rc: RangeEncoder): void;
112
+ encode(rc: RangeEncoder): void;
113
+ getPrice(curByte: number, matchByte: number, prevByte: number, pos: number, state: number): number;
114
+ }
115
+ export declare class LengthEncoder extends LengthCoder {
116
+ /**
117
+ * The prices are updated after at least
118
+ * `PRICE_UPDATE_INTERVAL` many lengths
119
+ * have been encoded with the same posState.
120
+ */
121
+ private static readonly PRICE_UPDATE_INTERVAL;
91
122
  private readonly counters;
123
+ private readonly prices;
92
124
  /** Whether a length was encoded since the last reset. */
93
125
  private used;
94
- /** Prices per position state, `[posState * lenSymbols + len - MATCH_LEN_MIN]`. */
95
- readonly prices: Uint32Array;
96
- readonly lenSymbols: number;
97
126
  constructor(probs: Probs, coder: number, pb: number, niceLen: number);
98
127
  reset(): void;
99
128
  encode(rc: RangeEncoder, lenIn: number, posState: number): void;
100
129
  getPrice(len: number, posState: number): number;
101
- /** Offset in `prices` such that `prices[offset + len]` is the price of `len`. */
102
- priceOffset(posState: number): number;
130
+ getPriceRow(posState: number): Int32Array;
103
131
  updatePrices(): void;
104
132
  private updatePosStatePrices;
105
133
  }