rar-stream 4.0.0 → 4.0.2
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 +131 -50
- package/package.json +10 -9
- package/rar-stream.darwin-arm64.node +0 -0
- package/rar-stream.darwin-x64.node +0 -0
- package/rar-stream.linux-arm64-gnu.node +0 -0
- package/rar-stream.linux-x64-gnu.node +0 -0
- package/rar-stream.linux-x64-musl.node +0 -0
- package/rar-stream.win32-x64-msvc.node +0 -0
- package/pkg/rar_stream.d.ts +0 -90
- package/pkg/rar_stream.js +0 -308
- package/pkg/rar_stream_bg.wasm +0 -0
- package/pkg/rar_stream_bg.wasm.d.ts +0 -19
package/README.md
CHANGED
|
@@ -30,24 +30,133 @@ pnpm add rar-stream
|
|
|
30
30
|
```javascript
|
|
31
31
|
import { LocalFileMedia, RarFilesPackage } from 'rar-stream';
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
// Open a RAR archive
|
|
34
34
|
const media = new LocalFileMedia('./archive.rar');
|
|
35
35
|
const pkg = new RarFilesPackage([media]);
|
|
36
36
|
|
|
37
|
-
// Parse
|
|
37
|
+
// Parse and list inner files
|
|
38
38
|
const files = await pkg.parse();
|
|
39
39
|
|
|
40
40
|
for (const file of files) {
|
|
41
41
|
console.log(`${file.name}: ${file.length} bytes`);
|
|
42
42
|
|
|
43
|
-
// Read entire file
|
|
43
|
+
// Read entire file into memory
|
|
44
44
|
const buffer = await file.readToEnd();
|
|
45
45
|
|
|
46
|
-
// Or read a specific range
|
|
47
|
-
const chunk = await file.createReadStream({ start: 0, end:
|
|
46
|
+
// Or read a specific byte range (for streaming)
|
|
47
|
+
const chunk = await file.createReadStream({ start: 0, end: 1023 });
|
|
48
48
|
}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
## Examples
|
|
52
|
+
|
|
53
|
+
### Extract a File to Disk
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
import { LocalFileMedia, RarFilesPackage } from 'rar-stream';
|
|
57
|
+
import fs from 'fs';
|
|
58
|
+
|
|
59
|
+
const media = new LocalFileMedia('./archive.rar');
|
|
60
|
+
const pkg = new RarFilesPackage([media]);
|
|
61
|
+
const files = await pkg.parse();
|
|
62
|
+
|
|
63
|
+
// Find a specific file
|
|
64
|
+
const targetFile = files.find(f => f.name.endsWith('.txt'));
|
|
65
|
+
if (targetFile) {
|
|
66
|
+
const content = await targetFile.readToEnd();
|
|
67
|
+
fs.writeFileSync('./extracted.txt', content);
|
|
68
|
+
console.log(`Extracted ${targetFile.name} (${content.length} bytes)`);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Stream Video from RAR (Partial Reads)
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
import { LocalFileMedia, RarFilesPackage } from 'rar-stream';
|
|
76
|
+
|
|
77
|
+
const media = new LocalFileMedia('./movie.rar');
|
|
78
|
+
const pkg = new RarFilesPackage([media]);
|
|
79
|
+
const files = await pkg.parse();
|
|
80
|
+
|
|
81
|
+
const video = files.find(f => f.name.endsWith('.mkv'));
|
|
82
|
+
if (video) {
|
|
83
|
+
// Read first 1MB for header analysis
|
|
84
|
+
const header = await video.createReadStream({ start: 0, end: 1024 * 1024 - 1 });
|
|
85
|
+
console.log(`Video: ${video.name}, Total size: ${video.length} bytes`);
|
|
86
|
+
|
|
87
|
+
// Stream in chunks
|
|
88
|
+
const chunkSize = 1024 * 1024; // 1MB chunks
|
|
89
|
+
for (let offset = 0; offset < video.length; offset += chunkSize) {
|
|
90
|
+
const end = Math.min(offset + chunkSize - 1, video.length - 1);
|
|
91
|
+
const chunk = await video.createReadStream({ start: offset, end });
|
|
92
|
+
// Process chunk...
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Multi-Volume Archives
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
import { LocalFileMedia, RarFilesPackage } from 'rar-stream';
|
|
101
|
+
import fs from 'fs';
|
|
102
|
+
import path from 'path';
|
|
103
|
+
|
|
104
|
+
// Find all volumes in a directory
|
|
105
|
+
const dir = './my-archive';
|
|
106
|
+
const volumeFiles = fs.readdirSync(dir)
|
|
107
|
+
.filter(f => /\.(rar|r\d{2})$/i.test(f))
|
|
108
|
+
.sort()
|
|
109
|
+
.map(f => new LocalFileMedia(path.join(dir, f)));
|
|
110
|
+
|
|
111
|
+
console.log(`Found ${volumeFiles.length} volumes`);
|
|
112
|
+
|
|
113
|
+
const pkg = new RarFilesPackage(volumeFiles);
|
|
114
|
+
const files = await pkg.parse();
|
|
115
|
+
|
|
116
|
+
// Files spanning multiple volumes are handled automatically
|
|
117
|
+
for (const file of files) {
|
|
118
|
+
console.log(`${file.name}: ${file.length} bytes`);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Check if a File is a RAR Archive
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
import { isRarArchive, parseRarHeader } from 'rar-stream';
|
|
126
|
+
import fs from 'fs';
|
|
127
|
+
|
|
128
|
+
// Read first 300 bytes (enough for header detection)
|
|
129
|
+
const buffer = Buffer.alloc(300);
|
|
130
|
+
const fd = fs.openSync('./unknown-file', 'r');
|
|
131
|
+
fs.readSync(fd, buffer, 0, 300, 0);
|
|
132
|
+
fs.closeSync(fd);
|
|
133
|
+
|
|
134
|
+
if (isRarArchive(buffer)) {
|
|
135
|
+
const info = parseRarHeader(buffer);
|
|
136
|
+
if (info) {
|
|
137
|
+
console.log(`First file: ${info.name}`);
|
|
138
|
+
console.log(`Packed size: ${info.packedSize} bytes`);
|
|
139
|
+
console.log(`Unpacked size: ${info.unpackedSize} bytes`);
|
|
140
|
+
console.log(`Compression method: 0x${info.method.toString(16)}`);
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
console.log('Not a RAR archive');
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Limit Number of Files Parsed
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
import { LocalFileMedia, RarFilesPackage } from 'rar-stream';
|
|
151
|
+
|
|
152
|
+
const media = new LocalFileMedia('./large-archive.rar');
|
|
153
|
+
const pkg = new RarFilesPackage([media]);
|
|
154
|
+
|
|
155
|
+
// Only parse first 10 files (useful for previewing large archives)
|
|
156
|
+
const files = await pkg.parse({ maxFiles: 10 });
|
|
157
|
+
console.log(`Showing first ${files.length} files`);
|
|
158
|
+
```
|
|
159
|
+
|
|
51
160
|
## API Reference
|
|
52
161
|
|
|
53
162
|
### LocalFileMedia
|
|
@@ -58,8 +167,8 @@ Represents a local RAR file.
|
|
|
58
167
|
class LocalFileMedia {
|
|
59
168
|
constructor(path: string);
|
|
60
169
|
|
|
61
|
-
readonly name: string;
|
|
62
|
-
readonly length: number;
|
|
170
|
+
readonly name: string; // Filename (basename)
|
|
171
|
+
readonly length: number; // File size in bytes
|
|
63
172
|
|
|
64
173
|
createReadStream(opts: { start: number; end: number }): Promise<Buffer>;
|
|
65
174
|
}
|
|
@@ -74,7 +183,7 @@ class RarFilesPackage {
|
|
|
74
183
|
constructor(files: LocalFileMedia[]);
|
|
75
184
|
|
|
76
185
|
parse(opts?: {
|
|
77
|
-
maxFiles?: number;
|
|
186
|
+
maxFiles?: number; // Limit number of files to parse
|
|
78
187
|
}): Promise<InnerFile[]>;
|
|
79
188
|
}
|
|
80
189
|
```
|
|
@@ -85,8 +194,8 @@ Represents a file inside the RAR archive.
|
|
|
85
194
|
|
|
86
195
|
```typescript
|
|
87
196
|
class InnerFile {
|
|
88
|
-
readonly name: string;
|
|
89
|
-
readonly length: number;
|
|
197
|
+
readonly name: string; // Full path inside archive
|
|
198
|
+
readonly length: number; // Uncompressed size in bytes
|
|
90
199
|
|
|
91
200
|
readToEnd(): Promise<Buffer>;
|
|
92
201
|
createReadStream(opts: { start: number; end: number }): Promise<Buffer>;
|
|
@@ -96,45 +205,18 @@ class InnerFile {
|
|
|
96
205
|
### Utility Functions
|
|
97
206
|
|
|
98
207
|
```typescript
|
|
99
|
-
// Check if buffer
|
|
208
|
+
// Check if buffer starts with RAR signature
|
|
100
209
|
function isRarArchive(buffer: Buffer): boolean;
|
|
101
210
|
|
|
102
|
-
// Parse RAR header from buffer (
|
|
211
|
+
// Parse RAR header from buffer (needs ~300 bytes)
|
|
103
212
|
function parseRarHeader(buffer: Buffer): RarFileInfo | null;
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Multi-Volume Archives
|
|
107
|
-
|
|
108
|
-
```javascript
|
|
109
|
-
import { LocalFileMedia, RarFilesPackage } from 'rar-stream';
|
|
110
|
-
|
|
111
|
-
// Load all volumes
|
|
112
|
-
const volumes = [
|
|
113
|
-
new LocalFileMedia('./archive.rar'),
|
|
114
|
-
new LocalFileMedia('./archive.r00'),
|
|
115
|
-
new LocalFileMedia('./archive.r01'),
|
|
116
|
-
];
|
|
117
|
-
|
|
118
|
-
const pkg = new RarFilesPackage(volumes);
|
|
119
|
-
const files = await pkg.parse();
|
|
120
213
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
```javascript
|
|
128
|
-
import init, { isRarArchive, WasmRarDecoder } from 'rar-stream/wasm';
|
|
129
|
-
|
|
130
|
-
await init();
|
|
131
|
-
|
|
132
|
-
// Check if data is a RAR archive
|
|
133
|
-
const buffer = new Uint8Array(/* ... */);
|
|
134
|
-
if (isRarArchive(buffer)) {
|
|
135
|
-
// Create decoder
|
|
136
|
-
const decoder = new WasmRarDecoder(unpackedSize);
|
|
137
|
-
const decompressed = decoder.decompress(compressedData);
|
|
214
|
+
interface RarFileInfo {
|
|
215
|
+
name: string;
|
|
216
|
+
packedSize: number;
|
|
217
|
+
unpackedSize: number;
|
|
218
|
+
method: number;
|
|
219
|
+
continuesInNext: boolean;
|
|
138
220
|
}
|
|
139
221
|
```
|
|
140
222
|
|
|
@@ -149,9 +231,9 @@ if (isRarArchive(buffer)) {
|
|
|
149
231
|
|
|
150
232
|
## Performance
|
|
151
233
|
|
|
152
|
-
Benchmarks on M1 MacBook Pro:
|
|
234
|
+
Benchmarks on M1 MacBook Pro (v4.x vs v3.x):
|
|
153
235
|
|
|
154
|
-
| Operation | rar-stream
|
|
236
|
+
| Operation | rar-stream v4 (Rust) | rar-stream v3 (JS) |
|
|
155
237
|
|-----------|---------------------|-------------------|
|
|
156
238
|
| Parse 1GB archive | ~50ms | ~200ms |
|
|
157
239
|
| Decompress 100MB | ~800ms | ~3000ms |
|
|
@@ -159,7 +241,7 @@ Benchmarks on M1 MacBook Pro:
|
|
|
159
241
|
|
|
160
242
|
## Migrating from v3.x
|
|
161
243
|
|
|
162
|
-
rar-stream v4
|
|
244
|
+
rar-stream v4 is a complete Rust rewrite with the same API. It's a drop-in replacement:
|
|
163
245
|
|
|
164
246
|
```javascript
|
|
165
247
|
// Works the same in v3.x and v4.x
|
|
@@ -173,12 +255,11 @@ const files = await pkg.parse();
|
|
|
173
255
|
### Breaking Changes
|
|
174
256
|
|
|
175
257
|
- Node.js 18+ required (was 14+)
|
|
176
|
-
- WASM module path changed to `rar-stream/wasm`
|
|
177
258
|
- Native Rust implementation (faster, lower memory)
|
|
178
259
|
|
|
179
260
|
## License
|
|
180
261
|
|
|
181
|
-
MIT
|
|
262
|
+
MIT
|
|
182
263
|
|
|
183
264
|
## Credits
|
|
184
265
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rar-stream",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "RAR streaming library - Rust implementation with NAPI and WASM bindings",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"browser": "browser.js",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"build": "napi build --platform --release --features napi",
|
|
57
57
|
"build:debug": "napi build --platform --features napi",
|
|
58
58
|
"build:wasm": "wasm-pack build --target web --features wasm --no-default-features",
|
|
59
|
-
"lint": "eslint .
|
|
59
|
+
"lint": "eslint .",
|
|
60
|
+
"lint:rust": "cargo clippy --features napi -- -D warnings && cargo clippy --features wasm --no-default-features -- -D warnings",
|
|
60
61
|
"lint:fix": "eslint . --fix",
|
|
61
62
|
"format": "cargo fmt && prettier --write '**/*.{ts,js,json,md}'",
|
|
62
63
|
"format:check": "cargo fmt --check && prettier --check '**/*.{ts,js,json,md}'",
|
|
@@ -88,12 +89,12 @@
|
|
|
88
89
|
"*.node"
|
|
89
90
|
],
|
|
90
91
|
"optionalDependencies": {
|
|
91
|
-
"rar-stream-win32-x64-msvc": "4.0.
|
|
92
|
-
"rar-stream-darwin-x64": "4.0.
|
|
93
|
-
"rar-stream-linux-x64-gnu": "4.0.
|
|
94
|
-
"rar-stream-linux-x64-musl": "4.0.
|
|
95
|
-
"rar-stream-linux-arm64-gnu": "4.0.
|
|
96
|
-
"rar-stream-darwin-arm64": "4.0.
|
|
97
|
-
"rar-stream-linux-arm64-musl": "4.0.
|
|
92
|
+
"rar-stream-win32-x64-msvc": "4.0.2",
|
|
93
|
+
"rar-stream-darwin-x64": "4.0.2",
|
|
94
|
+
"rar-stream-linux-x64-gnu": "4.0.2",
|
|
95
|
+
"rar-stream-linux-x64-musl": "4.0.2",
|
|
96
|
+
"rar-stream-linux-arm64-gnu": "4.0.2",
|
|
97
|
+
"rar-stream-darwin-arm64": "4.0.2",
|
|
98
|
+
"rar-stream-linux-arm64-musl": "4.0.2"
|
|
98
99
|
}
|
|
99
100
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/pkg/rar_stream.d.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* WASM-compatible RAR decompressor.
|
|
6
|
-
*/
|
|
7
|
-
export class WasmRarDecoder {
|
|
8
|
-
free(): void;
|
|
9
|
-
[Symbol.dispose](): void;
|
|
10
|
-
/**
|
|
11
|
-
* Get total bytes decompressed so far.
|
|
12
|
-
*/
|
|
13
|
-
bytes_written(): bigint;
|
|
14
|
-
/**
|
|
15
|
-
* Decompress a chunk of data.
|
|
16
|
-
*/
|
|
17
|
-
decompress(data: Uint8Array): Uint8Array;
|
|
18
|
-
/**
|
|
19
|
-
* Check if decompression is complete.
|
|
20
|
-
*/
|
|
21
|
-
is_complete(): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Create a new decoder for the specified unpacked size.
|
|
24
|
-
*/
|
|
25
|
-
constructor(unpacked_size: bigint);
|
|
26
|
-
/**
|
|
27
|
-
* Reset the decoder for a new file.
|
|
28
|
-
*/
|
|
29
|
-
reset(): void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Get the RAR format version from a buffer.
|
|
34
|
-
* Returns 15 for RAR 1.5-4.x, 50 for RAR 5.0+, or 0 if not a RAR archive.
|
|
35
|
-
*/
|
|
36
|
-
export function get_rar_version(data: Uint8Array): number;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Check if a buffer contains a RAR signature.
|
|
40
|
-
*/
|
|
41
|
-
export function is_rar_archive(data: Uint8Array): boolean;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Parse RAR file header information.
|
|
45
|
-
*/
|
|
46
|
-
export function parse_rar_header(data: Uint8Array): any;
|
|
47
|
-
|
|
48
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
49
|
-
|
|
50
|
-
export interface InitOutput {
|
|
51
|
-
readonly memory: WebAssembly.Memory;
|
|
52
|
-
readonly __wbg_wasmrardecoder_free: (a: number, b: number) => void;
|
|
53
|
-
readonly get_rar_version: (a: number, b: number) => number;
|
|
54
|
-
readonly is_rar_archive: (a: number, b: number) => number;
|
|
55
|
-
readonly parse_rar_header: (a: number, b: number) => [number, number, number];
|
|
56
|
-
readonly wasmrardecoder_bytes_written: (a: number) => bigint;
|
|
57
|
-
readonly wasmrardecoder_decompress: (a: number, b: number, c: number) => [number, number, number, number];
|
|
58
|
-
readonly wasmrardecoder_is_complete: (a: number) => number;
|
|
59
|
-
readonly wasmrardecoder_new: (a: bigint) => number;
|
|
60
|
-
readonly wasmrardecoder_reset: (a: number) => void;
|
|
61
|
-
readonly __wbindgen_exn_store: (a: number) => void;
|
|
62
|
-
readonly __externref_table_alloc: () => number;
|
|
63
|
-
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
64
|
-
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
65
|
-
readonly __externref_table_dealloc: (a: number) => void;
|
|
66
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
67
|
-
readonly __wbindgen_start: () => void;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
74
|
-
* a precompiled `WebAssembly.Module`.
|
|
75
|
-
*
|
|
76
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
77
|
-
*
|
|
78
|
-
* @returns {InitOutput}
|
|
79
|
-
*/
|
|
80
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
84
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
85
|
-
*
|
|
86
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
87
|
-
*
|
|
88
|
-
* @returns {Promise<InitOutput>}
|
|
89
|
-
*/
|
|
90
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/pkg/rar_stream.js
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./rar_stream.d.ts" */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* WASM-compatible RAR decompressor.
|
|
5
|
-
*/
|
|
6
|
-
export class WasmRarDecoder {
|
|
7
|
-
__destroy_into_raw() {
|
|
8
|
-
const ptr = this.__wbg_ptr;
|
|
9
|
-
this.__wbg_ptr = 0;
|
|
10
|
-
WasmRarDecoderFinalization.unregister(this);
|
|
11
|
-
return ptr;
|
|
12
|
-
}
|
|
13
|
-
free() {
|
|
14
|
-
const ptr = this.__destroy_into_raw();
|
|
15
|
-
wasm.__wbg_wasmrardecoder_free(ptr, 0);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Get total bytes decompressed so far.
|
|
19
|
-
* @returns {bigint}
|
|
20
|
-
*/
|
|
21
|
-
bytes_written() {
|
|
22
|
-
const ret = wasm.wasmrardecoder_bytes_written(this.__wbg_ptr);
|
|
23
|
-
return BigInt.asUintN(64, ret);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Decompress a chunk of data.
|
|
27
|
-
* @param {Uint8Array} data
|
|
28
|
-
* @returns {Uint8Array}
|
|
29
|
-
*/
|
|
30
|
-
decompress(data) {
|
|
31
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
32
|
-
const len0 = WASM_VECTOR_LEN;
|
|
33
|
-
const ret = wasm.wasmrardecoder_decompress(this.__wbg_ptr, ptr0, len0);
|
|
34
|
-
if (ret[3]) {
|
|
35
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
36
|
-
}
|
|
37
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
38
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
39
|
-
return v2;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Check if decompression is complete.
|
|
43
|
-
* @returns {boolean}
|
|
44
|
-
*/
|
|
45
|
-
is_complete() {
|
|
46
|
-
const ret = wasm.wasmrardecoder_is_complete(this.__wbg_ptr);
|
|
47
|
-
return ret !== 0;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Create a new decoder for the specified unpacked size.
|
|
51
|
-
* @param {bigint} unpacked_size
|
|
52
|
-
*/
|
|
53
|
-
constructor(unpacked_size) {
|
|
54
|
-
const ret = wasm.wasmrardecoder_new(unpacked_size);
|
|
55
|
-
this.__wbg_ptr = ret >>> 0;
|
|
56
|
-
WasmRarDecoderFinalization.register(this, this.__wbg_ptr, this);
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Reset the decoder for a new file.
|
|
61
|
-
*/
|
|
62
|
-
reset() {
|
|
63
|
-
wasm.wasmrardecoder_reset(this.__wbg_ptr);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (Symbol.dispose) WasmRarDecoder.prototype[Symbol.dispose] = WasmRarDecoder.prototype.free;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Get the RAR format version from a buffer.
|
|
70
|
-
* Returns 15 for RAR 1.5-4.x, 50 for RAR 5.0+, or 0 if not a RAR archive.
|
|
71
|
-
* @param {Uint8Array} data
|
|
72
|
-
* @returns {number}
|
|
73
|
-
*/
|
|
74
|
-
export function get_rar_version(data) {
|
|
75
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
76
|
-
const len0 = WASM_VECTOR_LEN;
|
|
77
|
-
const ret = wasm.get_rar_version(ptr0, len0);
|
|
78
|
-
return ret;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Check if a buffer contains a RAR signature.
|
|
83
|
-
* @param {Uint8Array} data
|
|
84
|
-
* @returns {boolean}
|
|
85
|
-
*/
|
|
86
|
-
export function is_rar_archive(data) {
|
|
87
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
88
|
-
const len0 = WASM_VECTOR_LEN;
|
|
89
|
-
const ret = wasm.is_rar_archive(ptr0, len0);
|
|
90
|
-
return ret !== 0;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Parse RAR file header information.
|
|
95
|
-
* @param {Uint8Array} data
|
|
96
|
-
* @returns {any}
|
|
97
|
-
*/
|
|
98
|
-
export function parse_rar_header(data) {
|
|
99
|
-
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
100
|
-
const len0 = WASM_VECTOR_LEN;
|
|
101
|
-
const ret = wasm.parse_rar_header(ptr0, len0);
|
|
102
|
-
if (ret[2]) {
|
|
103
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
104
|
-
}
|
|
105
|
-
return takeFromExternrefTable0(ret[0]);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function __wbg_get_imports() {
|
|
109
|
-
const import0 = {
|
|
110
|
-
__proto__: null,
|
|
111
|
-
__wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
|
|
112
|
-
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
113
|
-
return ret;
|
|
114
|
-
},
|
|
115
|
-
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
116
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
117
|
-
},
|
|
118
|
-
__wbg_new_361308b2356cecd0: function() {
|
|
119
|
-
const ret = new Object();
|
|
120
|
-
return ret;
|
|
121
|
-
},
|
|
122
|
-
__wbg_set_6cb8631f80447a67: function() { return handleError(function (arg0, arg1, arg2) {
|
|
123
|
-
const ret = Reflect.set(arg0, arg1, arg2);
|
|
124
|
-
return ret;
|
|
125
|
-
}, arguments); },
|
|
126
|
-
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
127
|
-
// Cast intrinsic for `F64 -> Externref`.
|
|
128
|
-
const ret = arg0;
|
|
129
|
-
return ret;
|
|
130
|
-
},
|
|
131
|
-
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
132
|
-
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
133
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
134
|
-
return ret;
|
|
135
|
-
},
|
|
136
|
-
__wbindgen_init_externref_table: function() {
|
|
137
|
-
const table = wasm.__wbindgen_externrefs;
|
|
138
|
-
const offset = table.grow(4);
|
|
139
|
-
table.set(0, undefined);
|
|
140
|
-
table.set(offset + 0, undefined);
|
|
141
|
-
table.set(offset + 1, null);
|
|
142
|
-
table.set(offset + 2, true);
|
|
143
|
-
table.set(offset + 3, false);
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
return {
|
|
147
|
-
__proto__: null,
|
|
148
|
-
"./rar_stream_bg.js": import0,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const WasmRarDecoderFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
153
|
-
? { register: () => {}, unregister: () => {} }
|
|
154
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_wasmrardecoder_free(ptr >>> 0, 1));
|
|
155
|
-
|
|
156
|
-
function addToExternrefTable0(obj) {
|
|
157
|
-
const idx = wasm.__externref_table_alloc();
|
|
158
|
-
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
159
|
-
return idx;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
163
|
-
ptr = ptr >>> 0;
|
|
164
|
-
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function getStringFromWasm0(ptr, len) {
|
|
168
|
-
ptr = ptr >>> 0;
|
|
169
|
-
return decodeText(ptr, len);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let cachedUint8ArrayMemory0 = null;
|
|
173
|
-
function getUint8ArrayMemory0() {
|
|
174
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
175
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
176
|
-
}
|
|
177
|
-
return cachedUint8ArrayMemory0;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function handleError(f, args) {
|
|
181
|
-
try {
|
|
182
|
-
return f.apply(this, args);
|
|
183
|
-
} catch (e) {
|
|
184
|
-
const idx = addToExternrefTable0(e);
|
|
185
|
-
wasm.__wbindgen_exn_store(idx);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
190
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
191
|
-
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
192
|
-
WASM_VECTOR_LEN = arg.length;
|
|
193
|
-
return ptr;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function takeFromExternrefTable0(idx) {
|
|
197
|
-
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
198
|
-
wasm.__externref_table_dealloc(idx);
|
|
199
|
-
return value;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
203
|
-
cachedTextDecoder.decode();
|
|
204
|
-
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
205
|
-
let numBytesDecoded = 0;
|
|
206
|
-
function decodeText(ptr, len) {
|
|
207
|
-
numBytesDecoded += len;
|
|
208
|
-
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
209
|
-
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
210
|
-
cachedTextDecoder.decode();
|
|
211
|
-
numBytesDecoded = len;
|
|
212
|
-
}
|
|
213
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
let WASM_VECTOR_LEN = 0;
|
|
217
|
-
|
|
218
|
-
let wasmModule, wasm;
|
|
219
|
-
function __wbg_finalize_init(instance, module) {
|
|
220
|
-
wasm = instance.exports;
|
|
221
|
-
wasmModule = module;
|
|
222
|
-
cachedUint8ArrayMemory0 = null;
|
|
223
|
-
wasm.__wbindgen_start();
|
|
224
|
-
return wasm;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async function __wbg_load(module, imports) {
|
|
228
|
-
if (typeof Response === 'function' && module instanceof Response) {
|
|
229
|
-
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
230
|
-
try {
|
|
231
|
-
return await WebAssembly.instantiateStreaming(module, imports);
|
|
232
|
-
} catch (e) {
|
|
233
|
-
const validResponse = module.ok && expectedResponseType(module.type);
|
|
234
|
-
|
|
235
|
-
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
236
|
-
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
237
|
-
|
|
238
|
-
} else { throw e; }
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const bytes = await module.arrayBuffer();
|
|
243
|
-
return await WebAssembly.instantiate(bytes, imports);
|
|
244
|
-
} else {
|
|
245
|
-
const instance = await WebAssembly.instantiate(module, imports);
|
|
246
|
-
|
|
247
|
-
if (instance instanceof WebAssembly.Instance) {
|
|
248
|
-
return { instance, module };
|
|
249
|
-
} else {
|
|
250
|
-
return instance;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
function expectedResponseType(type) {
|
|
255
|
-
switch (type) {
|
|
256
|
-
case 'basic': case 'cors': case 'default': return true;
|
|
257
|
-
}
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function initSync(module) {
|
|
263
|
-
if (wasm !== undefined) return wasm;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (module !== undefined) {
|
|
267
|
-
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
268
|
-
({module} = module)
|
|
269
|
-
} else {
|
|
270
|
-
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const imports = __wbg_get_imports();
|
|
275
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
276
|
-
module = new WebAssembly.Module(module);
|
|
277
|
-
}
|
|
278
|
-
const instance = new WebAssembly.Instance(module, imports);
|
|
279
|
-
return __wbg_finalize_init(instance, module);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
async function __wbg_init(module_or_path) {
|
|
283
|
-
if (wasm !== undefined) return wasm;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (module_or_path !== undefined) {
|
|
287
|
-
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
288
|
-
({module_or_path} = module_or_path)
|
|
289
|
-
} else {
|
|
290
|
-
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (module_or_path === undefined) {
|
|
295
|
-
module_or_path = new URL('rar_stream_bg.wasm', import.meta.url);
|
|
296
|
-
}
|
|
297
|
-
const imports = __wbg_get_imports();
|
|
298
|
-
|
|
299
|
-
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
300
|
-
module_or_path = fetch(module_or_path);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
304
|
-
|
|
305
|
-
return __wbg_finalize_init(instance, module);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export { initSync, __wbg_init as default };
|
package/pkg/rar_stream_bg.wasm
DELETED
|
Binary file
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
export const memory: WebAssembly.Memory;
|
|
4
|
-
export const __wbg_wasmrardecoder_free: (a: number, b: number) => void;
|
|
5
|
-
export const get_rar_version: (a: number, b: number) => number;
|
|
6
|
-
export const is_rar_archive: (a: number, b: number) => number;
|
|
7
|
-
export const parse_rar_header: (a: number, b: number) => [number, number, number];
|
|
8
|
-
export const wasmrardecoder_bytes_written: (a: number) => bigint;
|
|
9
|
-
export const wasmrardecoder_decompress: (a: number, b: number, c: number) => [number, number, number, number];
|
|
10
|
-
export const wasmrardecoder_is_complete: (a: number) => number;
|
|
11
|
-
export const wasmrardecoder_new: (a: bigint) => number;
|
|
12
|
-
export const wasmrardecoder_reset: (a: number) => void;
|
|
13
|
-
export const __wbindgen_exn_store: (a: number) => void;
|
|
14
|
-
export const __externref_table_alloc: () => number;
|
|
15
|
-
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
16
|
-
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
17
|
-
export const __externref_table_dealloc: (a: number) => void;
|
|
18
|
-
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
19
|
-
export const __wbindgen_start: () => void;
|