lzma1 0.0.3 → 0.0.4

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/README.md CHANGED
@@ -2,35 +2,49 @@
2
2
 
3
3
  This is a simplified [fork][fork-link] of [Nathan Rugg's][fork-author] package.
4
4
 
5
- The goal of this fork is to simplify and extract the minimal implementation for
6
- my second project, I'm also trying to add as many typings as possible.
5
+ [fork-link]: https://github.com/LZMA-JS/LZMA-JS
6
+ [fork-author]: https://github.com/nmrugg
7
+
8
+ ## Installation
7
9
 
8
- ## Install
10
+ > [!NOTE]
11
+ > This package is native [ESM][mozzila-esm] and no longer provides a
12
+ > CommonJS export. If your project uses CommonJS, you will have to convert to ESM
13
+ > or use the dynamic [`import()`][mozzila-import] function.
9
14
 
10
- **npm registry**
15
+ [mozzila-esm]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
16
+ [mozzila-import]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
17
+
18
+ ### npm
11
19
 
12
20
  ```sh
13
21
  npm install lzma1
14
22
  ```
15
23
 
16
- **GitHub**
24
+ ### deno
17
25
 
18
- ```sh
19
- # same as latest released npm registry version
20
- npm install xseman/lzma1#master
26
+ Since `v1.28+` import from npm registry using `npm:` prefix.
21
27
 
22
- # latest unreleased changes
23
- npm install xseman/lzma1#develop
28
+ ```ts
29
+ import {
30
+ compress,
31
+ decompress,
32
+ } from "npm:lzma1@latest";
33
+ ```
34
+
35
+ ### browser
24
36
 
25
- # specific tag version
26
- npm install xseman/lzma1#0.0.1
37
+ ```html
38
+ <script type="module">
39
+ import { compress, decompress } from "https://esm.sh/lzma1@latest";
40
+ </script>
27
41
  ```
28
42
 
29
43
  ## API
30
44
 
31
45
  ```ts
32
46
  compress(data: string | Uint8Array, mode?: Mode): Int8Array
33
- decompress(bytearray: Uint8Array): Int8Array
47
+ decompress(data: Uint8Array | ArrayBuffer): string | Int8Array
34
48
  ```
35
49
 
36
50
  ## Usage
@@ -38,14 +52,20 @@ decompress(bytearray: Uint8Array): Int8Array
38
52
  Compress and decompress a string with compression level 1.
39
53
 
40
54
  ```js
41
- import { compress, decompress } from "lzma1"
55
+ import {
56
+ compress,
57
+ decompress,
58
+ } from "lzma1";
42
59
 
43
- const data = "Hello World!"
44
- const compressed = compress(data, 1)
45
- const decompressed = decompress(result)
60
+ const data = "Hello World!";
61
+ const compressed = compress(data, 1);
62
+ const decompressed = decompress(result);
46
63
 
47
64
  // data === decompressed
48
65
  ```
49
66
 
50
- [fork-link]: https://github.com/LZMA-JS/LZMA-JS
51
- [fork-author]: https://github.com/nmrugg
67
+ ## Related
68
+
69
+ - <https://github.com/cscott/lzma-purejs>
70
+ - <https://github.com/glinscott/lzmajs>
71
+ - <https://github.com/mauron85/lzma-purejs/tree/master>
package/dist/lzma.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ export declare class LZMA {
2
+ #private;
3
+ readonly CompressionModes: {
4
+ readonly 1: {
5
+ readonly searchDepth: 16;
6
+ readonly filterStrength: 64;
7
+ readonly modeIndex: 0;
8
+ };
9
+ readonly 2: {
10
+ readonly searchDepth: 20;
11
+ readonly filterStrength: 64;
12
+ readonly modeIndex: 0;
13
+ };
14
+ readonly 3: {
15
+ readonly searchDepth: 19;
16
+ readonly filterStrength: 64;
17
+ readonly modeIndex: 1;
18
+ };
19
+ readonly 4: {
20
+ readonly searchDepth: 20;
21
+ readonly filterStrength: 64;
22
+ readonly modeIndex: 1;
23
+ };
24
+ readonly 5: {
25
+ readonly searchDepth: 21;
26
+ readonly filterStrength: 128;
27
+ readonly modeIndex: 1;
28
+ };
29
+ readonly 6: {
30
+ readonly searchDepth: 22;
31
+ readonly filterStrength: 128;
32
+ readonly modeIndex: 1;
33
+ };
34
+ readonly 7: {
35
+ readonly searchDepth: 23;
36
+ readonly filterStrength: 128;
37
+ readonly modeIndex: 1;
38
+ };
39
+ readonly 8: {
40
+ readonly searchDepth: 24;
41
+ readonly filterStrength: 255;
42
+ readonly modeIndex: 1;
43
+ };
44
+ readonly 9: {
45
+ readonly searchDepth: 25;
46
+ readonly filterStrength: 255;
47
+ readonly modeIndex: 1;
48
+ };
49
+ };
50
+ constructor();
51
+ GetLenToPosState(len: number): number;
52
+ StateUpdateChar(index: number): number;
53
+ writeHeaderProperties(): void;
54
+ GetPosSlot(pos: number): number;
55
+ GetPosSlot2(pos: number): number;
56
+ reverseDecode(Models: number[], startIndex: number, NumBitLevels: number): number;
57
+ ReverseEncode(startIndex: number, NumBitLevels: number, symbol: number): void;
58
+ ReverseGetPrice(Models: number[], startIndex: number, NumBitLevels: number, symbol: number): number;
59
+ InitBitModels(probs: number[]): void;
60
+ GetPrice(Prob: number, symbol: number): number;
61
+ encode(inputString: string | Uint8Array): number[] | Uint8Array;
62
+ compress(data: string | Uint8Array | ArrayBuffer, mode?: keyof typeof this.CompressionModes): Int8Array;
63
+ decompress(bytearray: Uint8Array | ArrayBuffer): Int8Array | string;
64
+ }
65
+ type CompressionMode = keyof LZMA["CompressionModes"];
66
+ /**
67
+ * Compresses data using LZMA algorithm
68
+ *
69
+ * @param data Data to compress - can be string, Uint8Array or ArrayBuffer
70
+ * @param mode Compression mode (1-9), defaults to 5
71
+ * @returns Compressed data as Int8Array
72
+ */
73
+ export declare function compress(data: string | Uint8Array | ArrayBuffer, mode?: CompressionMode): Int8Array;
74
+ /**
75
+ * Decompresses LZMA compressed data
76
+ *
77
+ * @param data Compressed data as Uint8Array or ArrayBuffer
78
+ * @returns Decompressed data as string if input was string, or Int8Array if input was binary
79
+ */
80
+ export declare function decompress(data: Uint8Array | ArrayBuffer): string | Int8Array;
81
+ export {};