lzma1 0.2.0 → 0.3.0

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.
package/lib/utils.js CHANGED
@@ -1,7 +1,3 @@
1
- // Constants for 64-bit arithmetic
2
- const MAX_UINT32 = 0x100000000;
3
- const MAX_INT32 = 0x7FFFFFFF;
4
- const MIN_INT32 = -0x80000000;
5
1
  // Additional LZMA constants
6
2
  export const INFINITY_PRICE = 0xFFFFFFF;
7
3
  export const _MAX_UINT32 = 0xFFFFFFFF;
@@ -20,12 +16,6 @@ export const POS_DECODERS_SIZE = 114;
20
16
  export const LITERAL_DECODER_SIZE = 0x300; // 768
21
17
  export const DEFAULT_WINDOW_SIZE = 0x1000; // 4096
22
18
  export const CHOICE_ARRAY_SIZE = 2;
23
- // Special 64-bit number constants
24
- export const N1_LONG_LIT = [0xFFFFFFFF, -MAX_UINT32];
25
- export const MIN_VALUE = [0, -0x8000000000000000];
26
- export const P0_LONG_LIT = [0, 0];
27
- export const P1_LONG_LIT = [1, 0];
28
- export const ZERO_64 = [0, 0];
29
19
  /**
30
20
  * CRC32 lookup table for hash calculations
31
21
  * dprint-ignore
@@ -130,98 +120,6 @@ export function arraycopy(src, srcOfs, dest, destOfs, len) {
130
120
  export function getBitPrice(probability, bit) {
131
121
  return PROB_PRICES[((probability - bit ^ -bit) & 2047) >>> 2];
132
122
  }
133
- /**
134
- * Create a 64-bit number from low and high parts
135
- */
136
- export function create64(valueLow, valueHigh) {
137
- let diffHigh, diffLow;
138
- valueHigh %= 1.8446744073709552E19;
139
- valueLow %= 1.8446744073709552E19;
140
- diffHigh = valueHigh % MAX_UINT32;
141
- diffLow = Math.floor(valueLow / MAX_UINT32) * MAX_UINT32;
142
- valueHigh = valueHigh - diffHigh + diffLow;
143
- valueLow = valueLow - diffLow + diffHigh;
144
- while (valueLow < 0) {
145
- valueLow += MAX_UINT32;
146
- valueHigh -= MAX_UINT32;
147
- }
148
- while (valueLow > 0xFFFFFFFF) {
149
- valueLow -= MAX_UINT32;
150
- valueHigh += MAX_UINT32;
151
- }
152
- valueHigh = valueHigh % 1.8446744073709552E19;
153
- while (valueHigh > 9223372032559808512) {
154
- valueHigh -= 1.8446744073709552E19;
155
- }
156
- while (valueHigh < -9223372036854775808) {
157
- valueHigh += 1.8446744073709552E19;
158
- }
159
- return [valueLow, valueHigh];
160
- }
161
- /**
162
- * Add two 64-bit numbers
163
- */
164
- export function add64(a, b) {
165
- return create64(a[0] + b[0], a[1] + b[1]);
166
- }
167
- /**
168
- * Subtract two 64-bit numbers
169
- */
170
- export function sub64(a, b) {
171
- return create64(a[0] - b[0], a[1] - b[1]);
172
- }
173
- /**
174
- * Compare two 64-bit numbers
175
- */
176
- export function compare64(a, b) {
177
- if (a[0] == b[0] && a[1] == b[1]) {
178
- return 0;
179
- }
180
- const nega = a[1] < 0;
181
- const negb = b[1] < 0;
182
- if (nega && !negb) {
183
- return -1;
184
- }
185
- if (!nega && negb) {
186
- return 1;
187
- }
188
- if (sub64(a, b)[1] < 0) {
189
- return -1;
190
- }
191
- return 1;
192
- }
193
- /**
194
- * Extract low bits from 64-bit number
195
- */
196
- export function lowBits64(a) {
197
- if (a[0] >= 0x80000000) {
198
- return ~~Math.max(Math.min(a[0] - MAX_UINT32, MAX_INT32), MIN_INT32);
199
- }
200
- return ~~Math.max(Math.min(a[0], MAX_INT32), MIN_INT32);
201
- }
202
- /**
203
- * Create 64-bit number from integer
204
- */
205
- export function fromInt64(value) {
206
- if (value >= 0) {
207
- return [value, 0];
208
- }
209
- else {
210
- return [value + MAX_UINT32, -MAX_UINT32];
211
- }
212
- }
213
- /**
214
- * Right shift 64-bit number
215
- */
216
- export function shr64(a, n) {
217
- n &= 0x3F;
218
- if (n <= 0x1E) {
219
- const shiftFact = 1 << n;
220
- return create64(Math.floor(a[0] / shiftFact), a[1] / shiftFact);
221
- }
222
- const shiftFact = (1 << 0x1E) * (1 << (n - 0x1E));
223
- return create64(Math.floor(a[0] / shiftFact), a[1] / shiftFact);
224
- }
225
123
  /**
226
124
  * Bit model operations
227
125
  */
@@ -249,7 +147,11 @@ export function getLenToPosState(len) {
249
147
  /**
250
148
  * Update state after character encoding/decoding
251
149
  */
150
+ const STATE_UPDATE_CHAR_TABLE = [0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5];
252
151
  export function stateUpdateChar(index) {
152
+ if (index >= 0 && index < STATE_UPDATE_CHAR_TABLE.length) {
153
+ return STATE_UPDATE_CHAR_TABLE[index];
154
+ }
253
155
  if (index < 4) {
254
156
  return 0;
255
157
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "lzma1",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "license": "MIT",
6
6
  "author": "Filip Seman <filip.seman@pm.me>",
7
7
  "description": "A JavaScript implementation of the Lempel-Ziv-Markov (LZMA) chain compression algorithm",
8
8
  "funding": "https://github.com/sponsors/xseman",
9
- "homepage": "https://github.com/xseman/lzma1#readme",
9
+ "homepage": "https://github.com/xseman/lzma1",
10
10
  "keywords": [
11
11
  "lzma",
12
12
  "lzma1",
@@ -14,32 +14,43 @@
14
14
  ],
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+https://github.com/xseman/lzma1.git"
17
+ "url": "https://github.com/xseman/lzma1"
18
18
  },
19
19
  "scripts": {
20
20
  "prebuild": "tsc --build --clean",
21
- "build": "tsc",
21
+ "build": "tsc --build",
22
22
  "fmt": "dprint fmt",
23
23
  "fmt:check": "dprint check",
24
24
  "typecheck": "tsc --noEmit",
25
- "test": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov ./src/lzma.test.ts",
26
- "test:watch": "bun test --watch ./src/lzma.test.ts"
25
+ "bench": "bun test src/bench_test.ts --no-coverage --timeout 300000",
26
+ "test": "bun test src/ --coverage --coverage-reporter=text --coverage-reporter=lcov --concurrent --path-ignore-patterns=src/bench_test.ts",
27
+ "test:watch": "bun test src/ --watch --coverage --concurrent --path-ignore-patterns=src/bench_test.ts"
27
28
  },
28
29
  "devDependencies": {
29
- "@types/bun": "^1.2.18",
30
- "@types/node": "^24.0.14",
31
- "dprint": "~0.50.0",
32
- "typescript": "^5.8.0"
30
+ "@types/bun": "^1.3.11",
31
+ "@types/node": "^25.5.2",
32
+ "dprint": "~0.54.0",
33
+ "typescript": "^6.0.2"
33
34
  },
35
+ "engines": {
36
+ "bun": ">=1.0.0",
37
+ "node": ">=18.0.0"
38
+ },
39
+ "sideEffects": false,
40
+ "types": "./src/index.ts",
34
41
  "exports": {
35
42
  "./package.json": "./package.json",
36
43
  ".": {
44
+ "types": "./src/index.ts",
45
+ "bun": "./src/index.ts",
37
46
  "import": "./lib/index.js",
38
- "types": "./lib/index.d.ts"
47
+ "require": "./lib/index.js"
39
48
  }
40
49
  },
41
50
  "files": [
42
- "lib",
43
- "!lib/*test*"
51
+ "lib/**/*.js",
52
+ "!lib/**/*_test*",
53
+ "src/**/*.ts",
54
+ "!src/**/*_test.ts"
44
55
  ]
45
56
  }