lzma1 0.0.3 → 0.0.5

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