@push.rocks/smartarchive 4.2.3 → 5.0.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/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/bzip2/bititerator.d.ts +6 -1
- package/dist_ts/bzip2/bititerator.js +30 -24
- package/dist_ts/bzip2/bzip2.d.ts +27 -12
- package/dist_ts/bzip2/bzip2.js +325 -263
- package/dist_ts/bzip2/index.d.ts +4 -1
- package/dist_ts/bzip2/index.js +36 -38
- package/dist_ts/classes.archiveanalyzer.d.ts +25 -5
- package/dist_ts/classes.archiveanalyzer.js +19 -8
- package/dist_ts/classes.bzip2tools.d.ts +1 -1
- package/dist_ts/classes.gziptools.d.ts +39 -6
- package/dist_ts/classes.gziptools.js +85 -24
- package/dist_ts/classes.smartarchive.d.ts +101 -16
- package/dist_ts/classes.smartarchive.js +398 -61
- package/dist_ts/classes.tartools.d.ts +31 -4
- package/dist_ts/classes.tartools.js +97 -36
- package/dist_ts/classes.ziptools.d.ts +47 -12
- package/dist_ts/classes.ziptools.js +142 -23
- package/dist_ts/errors.d.ts +44 -0
- package/dist_ts/errors.js +62 -0
- package/dist_ts/index.d.ts +4 -0
- package/dist_ts/index.js +9 -1
- package/dist_ts/interfaces.d.ts +115 -0
- package/dist_ts/interfaces.js +2 -0
- package/dist_ts/plugins.d.ts +9 -3
- package/dist_ts/plugins.js +27 -4
- package/package.json +3 -4
- package/readme.hints.md +38 -1
- package/readme.md +248 -137
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/bzip2/bititerator.ts +43 -27
- package/ts/bzip2/bzip2.ts +289 -171
- package/ts/bzip2/index.ts +52 -50
- package/ts/classes.archiveanalyzer.ts +42 -28
- package/ts/classes.gziptools.ts +96 -33
- package/ts/classes.smartarchive.ts +472 -122
- package/ts/classes.tartools.ts +128 -59
- package/ts/classes.ziptools.ts +160 -34
- package/ts/errors.ts +70 -0
- package/ts/index.ts +11 -0
- package/ts/interfaces.ts +131 -0
- package/ts/plugins.ts +29 -3
package/readme.md
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
# @push.rocks/smartarchive 📦
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Powerful archive manipulation for modern Node.js applications.
|
|
4
4
|
|
|
5
5
|
`@push.rocks/smartarchive` is a versatile library for handling archive files with a focus on developer experience. Work with **zip**, **tar**, **gzip**, and **bzip2** formats through a unified, streaming-optimized API.
|
|
6
6
|
|
|
7
|
+
## Issue Reporting and Security
|
|
8
|
+
|
|
9
|
+
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
|
10
|
+
|
|
7
11
|
## Features 🚀
|
|
8
12
|
|
|
9
|
-
- 📁 **Multi-format support**
|
|
10
|
-
- 🌊 **Streaming-first architecture**
|
|
11
|
-
- 🔄 **Unified API**
|
|
12
|
-
- 🎯 **Smart detection**
|
|
13
|
-
- ⚡ **High performance**
|
|
14
|
-
- 🔧 **Flexible I/O**
|
|
15
|
-
-
|
|
16
|
-
- 🛠️ **Modern TypeScript** - Full type safety and excellent IDE support
|
|
13
|
+
- 📁 **Multi-format support** – Handle `.zip`, `.tar`, `.tar.gz`, `.tgz`, and `.bz2` archives
|
|
14
|
+
- 🌊 **Streaming-first architecture** – Process large archives without memory constraints
|
|
15
|
+
- 🔄 **Unified API** – Consistent interface across different archive formats
|
|
16
|
+
- 🎯 **Smart detection** – Automatically identifies archive types via magic bytes
|
|
17
|
+
- ⚡ **High performance** – Built on `tar-stream` and `fflate` for speed
|
|
18
|
+
- 🔧 **Flexible I/O** – Work with files, URLs, and streams seamlessly
|
|
19
|
+
- 🛠️ **Modern TypeScript** – Full type safety and excellent IDE support
|
|
17
20
|
|
|
18
21
|
## Installation 📥
|
|
19
22
|
|
|
20
23
|
```bash
|
|
21
|
-
# Using npm
|
|
22
|
-
npm install @push.rocks/smartarchive
|
|
23
|
-
|
|
24
24
|
# Using pnpm (recommended)
|
|
25
25
|
pnpm add @push.rocks/smartarchive
|
|
26
26
|
|
|
27
|
+
# Using npm
|
|
28
|
+
npm install @push.rocks/smartarchive
|
|
29
|
+
|
|
27
30
|
# Using yarn
|
|
28
31
|
yarn add @push.rocks/smartarchive
|
|
29
32
|
```
|
|
@@ -37,7 +40,7 @@ import { SmartArchive } from '@push.rocks/smartarchive';
|
|
|
37
40
|
|
|
38
41
|
// Extract a .tar.gz archive from a URL directly to the filesystem
|
|
39
42
|
const archive = await SmartArchive.fromArchiveUrl(
|
|
40
|
-
'https://
|
|
43
|
+
'https://registry.npmjs.org/some-package/-/some-package-1.0.0.tgz'
|
|
41
44
|
);
|
|
42
45
|
await archive.exportToFs('./extracted');
|
|
43
46
|
```
|
|
@@ -52,10 +55,15 @@ const archive = await SmartArchive.fromArchiveFile('./large-archive.zip');
|
|
|
52
55
|
const streamOfFiles = await archive.exportToStreamOfStreamFiles();
|
|
53
56
|
|
|
54
57
|
// Process each file in the archive
|
|
55
|
-
streamOfFiles.on('data', (
|
|
56
|
-
console.log(`Processing ${
|
|
58
|
+
streamOfFiles.on('data', async (streamFile) => {
|
|
59
|
+
console.log(`Processing ${streamFile.relativeFilePath}`);
|
|
60
|
+
const readStream = await streamFile.createReadStream();
|
|
57
61
|
// Handle individual file stream
|
|
58
62
|
});
|
|
63
|
+
|
|
64
|
+
streamOfFiles.on('end', () => {
|
|
65
|
+
console.log('Extraction complete');
|
|
66
|
+
});
|
|
59
67
|
```
|
|
60
68
|
|
|
61
69
|
## Core Concepts 💡
|
|
@@ -64,17 +72,18 @@ streamOfFiles.on('data', (fileStream) => {
|
|
|
64
72
|
|
|
65
73
|
`SmartArchive` accepts archives from three sources:
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
| Source | Method | Use Case |
|
|
76
|
+
|--------|--------|----------|
|
|
77
|
+
| **URL** | `SmartArchive.fromArchiveUrl(url)` | Download and process archives from the web |
|
|
78
|
+
| **File** | `SmartArchive.fromArchiveFile(path)` | Load archives from the local filesystem |
|
|
79
|
+
| **Stream** | `SmartArchive.fromArchiveStream(stream)` | Process archives from any Node.js stream |
|
|
70
80
|
|
|
71
81
|
### Export Destinations
|
|
72
82
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
3. **Archive stream** - Re-stream as different format
|
|
83
|
+
| Destination | Method | Use Case |
|
|
84
|
+
|-------------|--------|----------|
|
|
85
|
+
| **Filesystem** | `exportToFs(targetDir, fileName?)` | Extract directly to a directory |
|
|
86
|
+
| **Stream of files** | `exportToStreamOfStreamFiles()` | Process files individually as `StreamFile` objects |
|
|
78
87
|
|
|
79
88
|
## Usage Examples 🔨
|
|
80
89
|
|
|
@@ -89,10 +98,11 @@ await zipArchive.exportToFs('./output');
|
|
|
89
98
|
|
|
90
99
|
// Stream ZIP contents for processing
|
|
91
100
|
const fileStream = await zipArchive.exportToStreamOfStreamFiles();
|
|
92
|
-
|
|
93
|
-
|
|
101
|
+
|
|
102
|
+
fileStream.on('data', async (streamFile) => {
|
|
103
|
+
if (streamFile.relativeFilePath.endsWith('.json')) {
|
|
104
|
+
const readStream = await streamFile.createReadStream();
|
|
94
105
|
// Process JSON files from the archive
|
|
95
|
-
file.pipe(jsonProcessor);
|
|
96
106
|
}
|
|
97
107
|
});
|
|
98
108
|
```
|
|
@@ -106,58 +116,75 @@ import { SmartArchive, TarTools } from '@push.rocks/smartarchive';
|
|
|
106
116
|
const tarGzArchive = await SmartArchive.fromArchiveFile('./archive.tar.gz');
|
|
107
117
|
await tarGzArchive.exportToFs('./extracted');
|
|
108
118
|
|
|
109
|
-
// Create a TAR archive
|
|
119
|
+
// Create a TAR archive using TarTools directly
|
|
110
120
|
const tarTools = new TarTools();
|
|
111
|
-
const
|
|
112
|
-
|
|
121
|
+
const pack = await tarTools.getPackStream();
|
|
122
|
+
|
|
123
|
+
// Add files to the pack
|
|
124
|
+
await tarTools.addFileToPack(pack, {
|
|
125
|
+
fileName: 'hello.txt',
|
|
126
|
+
content: 'Hello, World!'
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
await tarTools.addFileToPack(pack, {
|
|
130
|
+
fileName: 'data.json',
|
|
131
|
+
content: Buffer.from(JSON.stringify({ foo: 'bar' }))
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Finalize and pipe to destination
|
|
135
|
+
pack.finalize();
|
|
136
|
+
pack.pipe(createWriteStream('./output.tar'));
|
|
113
137
|
```
|
|
114
138
|
|
|
115
|
-
###
|
|
139
|
+
### Pack a directory into TAR
|
|
116
140
|
|
|
117
141
|
```typescript
|
|
118
|
-
import {
|
|
119
|
-
|
|
120
|
-
// Download and extract in one operation
|
|
121
|
-
const remoteArchive = await SmartArchive.fromArchiveUrl(
|
|
122
|
-
'https://example.com/data.tar.gz'
|
|
123
|
-
);
|
|
142
|
+
import { TarTools } from '@push.rocks/smartarchive';
|
|
143
|
+
import { createWriteStream } from 'fs';
|
|
124
144
|
|
|
125
|
-
|
|
126
|
-
await remoteArchive.exportToFs('./local-dir');
|
|
145
|
+
const tarTools = new TarTools();
|
|
127
146
|
|
|
128
|
-
//
|
|
129
|
-
const
|
|
147
|
+
// Pack an entire directory
|
|
148
|
+
const pack = await tarTools.packDirectory('./src');
|
|
149
|
+
pack.finalize();
|
|
150
|
+
pack.pipe(createWriteStream('./source.tar'));
|
|
130
151
|
```
|
|
131
152
|
|
|
132
|
-
###
|
|
153
|
+
### Extracting from URLs
|
|
133
154
|
|
|
134
155
|
```typescript
|
|
135
156
|
import { SmartArchive } from '@push.rocks/smartarchive';
|
|
136
157
|
|
|
137
|
-
//
|
|
138
|
-
const
|
|
139
|
-
|
|
158
|
+
// Download and extract npm packages
|
|
159
|
+
const npmPackage = await SmartArchive.fromArchiveUrl(
|
|
160
|
+
'https://registry.npmjs.org/@push.rocks/smartfile/-/smartfile-11.2.7.tgz'
|
|
161
|
+
);
|
|
162
|
+
await npmPackage.exportToFs('./node_modules/@push.rocks/smartfile');
|
|
140
163
|
|
|
141
|
-
//
|
|
142
|
-
|
|
164
|
+
// Or process as stream for memory efficiency
|
|
165
|
+
const stream = await npmPackage.exportToStreamOfStreamFiles();
|
|
166
|
+
stream.on('data', async (file) => {
|
|
167
|
+
console.log(`Extracted: ${file.relativeFilePath}`);
|
|
168
|
+
});
|
|
143
169
|
```
|
|
144
170
|
|
|
145
171
|
### Working with GZIP files
|
|
146
172
|
|
|
147
173
|
```typescript
|
|
148
174
|
import { SmartArchive, GzipTools } from '@push.rocks/smartarchive';
|
|
175
|
+
import { createReadStream, createWriteStream } from 'fs';
|
|
149
176
|
|
|
150
|
-
// Decompress a .gz file
|
|
177
|
+
// Decompress a .gz file - provide filename since gzip doesn't store it
|
|
151
178
|
const gzipArchive = await SmartArchive.fromArchiveFile('./data.json.gz');
|
|
152
179
|
await gzipArchive.exportToFs('./decompressed', 'data.json');
|
|
153
180
|
|
|
154
|
-
// Use GzipTools directly for streaming
|
|
181
|
+
// Use GzipTools directly for streaming decompression
|
|
155
182
|
const gzipTools = new GzipTools();
|
|
156
183
|
const decompressStream = gzipTools.getDecompressionStream();
|
|
157
184
|
|
|
158
185
|
createReadStream('./compressed.gz')
|
|
159
186
|
.pipe(decompressStream)
|
|
160
|
-
.pipe(createWriteStream('./decompressed'));
|
|
187
|
+
.pipe(createWriteStream('./decompressed.txt'));
|
|
161
188
|
```
|
|
162
189
|
|
|
163
190
|
### Working with BZIP2 files
|
|
@@ -172,115 +199,175 @@ const bzipArchive = await SmartArchive.fromArchiveUrl(
|
|
|
172
199
|
await bzipArchive.exportToFs('./extracted', 'data.txt');
|
|
173
200
|
```
|
|
174
201
|
|
|
175
|
-
###
|
|
202
|
+
### In-memory processing (no filesystem)
|
|
176
203
|
|
|
177
204
|
```typescript
|
|
178
205
|
import { SmartArchive } from '@push.rocks/smartarchive';
|
|
179
|
-
import {
|
|
206
|
+
import { Readable } from 'stream';
|
|
180
207
|
|
|
181
|
-
//
|
|
182
|
-
const
|
|
183
|
-
const
|
|
208
|
+
// Process archives entirely in memory
|
|
209
|
+
const compressedBuffer = await fetchCompressedData();
|
|
210
|
+
const memoryStream = Readable.from(compressedBuffer);
|
|
184
211
|
|
|
185
|
-
|
|
186
|
-
await
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
212
|
+
const archive = await SmartArchive.fromArchiveStream(memoryStream);
|
|
213
|
+
const streamFiles = await archive.exportToStreamOfStreamFiles();
|
|
214
|
+
|
|
215
|
+
const extractedFiles: Array<{ name: string; content: Buffer }> = [];
|
|
216
|
+
|
|
217
|
+
streamFiles.on('data', async (streamFile) => {
|
|
218
|
+
const chunks: Buffer[] = [];
|
|
219
|
+
const readStream = await streamFile.createReadStream();
|
|
220
|
+
|
|
221
|
+
for await (const chunk of readStream) {
|
|
222
|
+
chunks.push(chunk);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
extractedFiles.push({
|
|
226
|
+
name: streamFile.relativeFilePath,
|
|
227
|
+
content: Buffer.concat(chunks)
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
await new Promise((resolve) => streamFiles.on('end', resolve));
|
|
232
|
+
console.log(`Extracted ${extractedFiles.length} files in memory`);
|
|
198
233
|
```
|
|
199
234
|
|
|
200
|
-
###
|
|
235
|
+
### Nested archive handling (e.g., .tar.gz)
|
|
236
|
+
|
|
237
|
+
The library automatically handles nested compression. A `.tar.gz` file is:
|
|
238
|
+
1. First decompressed from gzip
|
|
239
|
+
2. Then unpacked from tar
|
|
240
|
+
|
|
241
|
+
This happens transparently:
|
|
201
242
|
|
|
202
243
|
```typescript
|
|
203
244
|
import { SmartArchive } from '@push.rocks/smartarchive';
|
|
204
|
-
import { TarTools } from '@push.rocks/smartarchive';
|
|
205
245
|
|
|
206
|
-
//
|
|
207
|
-
const
|
|
246
|
+
// Automatically handles gzip → tar extraction chain
|
|
247
|
+
const tgzArchive = await SmartArchive.fromArchiveFile('./package.tar.gz');
|
|
248
|
+
await tgzArchive.exportToFs('./extracted');
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## API Reference 📚
|
|
252
|
+
|
|
253
|
+
### SmartArchive Class
|
|
254
|
+
|
|
255
|
+
The main entry point for archive operations.
|
|
208
256
|
|
|
209
|
-
|
|
210
|
-
archive.addedDirectories.push('./src');
|
|
211
|
-
archive.addedFiles.push('./readme.md');
|
|
212
|
-
archive.addedFiles.push('./package.json');
|
|
257
|
+
#### Static Factory Methods
|
|
213
258
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
259
|
+
```typescript
|
|
260
|
+
// Create from URL - downloads and processes archive
|
|
261
|
+
SmartArchive.fromArchiveUrl(url: string): Promise<SmartArchive>
|
|
262
|
+
|
|
263
|
+
// Create from local file path
|
|
264
|
+
SmartArchive.fromArchiveFile(path: string): Promise<SmartArchive>
|
|
265
|
+
|
|
266
|
+
// Create from any Node.js readable stream
|
|
267
|
+
SmartArchive.fromArchiveStream(stream: Readable | Duplex | Transform): Promise<SmartArchive>
|
|
217
268
|
```
|
|
218
269
|
|
|
219
|
-
|
|
270
|
+
#### Instance Methods
|
|
220
271
|
|
|
221
272
|
```typescript
|
|
222
|
-
|
|
223
|
-
|
|
273
|
+
// Extract all files to a directory
|
|
274
|
+
// fileName is optional - used for single-file archives (like .gz) that don't store filename
|
|
275
|
+
exportToFs(targetDir: string, fileName?: string): Promise<void>
|
|
224
276
|
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
'https://example.com/source-code.tar.gz'
|
|
228
|
-
);
|
|
277
|
+
// Get a stream that emits StreamFile objects for each file in the archive
|
|
278
|
+
exportToStreamOfStreamFiles(): Promise<StreamIntake<StreamFile>>
|
|
229
279
|
|
|
230
|
-
|
|
280
|
+
// Get the raw archive stream (useful for piping)
|
|
281
|
+
getArchiveStream(): Promise<Readable>
|
|
282
|
+
```
|
|
231
283
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
284
|
+
#### Instance Properties
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
archive.tarTools // TarTools instance for TAR-specific operations
|
|
288
|
+
archive.zipTools // ZipTools instance for ZIP-specific operations
|
|
289
|
+
archive.gzipTools // GzipTools instance for GZIP-specific operations
|
|
290
|
+
archive.bzip2Tools // Bzip2Tools instance for BZIP2-specific operations
|
|
291
|
+
archive.archiveAnalyzer // ArchiveAnalyzer for inspecting archive type
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### TarTools Class
|
|
295
|
+
|
|
296
|
+
TAR-specific operations for creating and extracting TAR archives.
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
import { TarTools } from '@push.rocks/smartarchive';
|
|
300
|
+
|
|
301
|
+
const tarTools = new TarTools();
|
|
302
|
+
|
|
303
|
+
// Get a tar pack stream for creating archives
|
|
304
|
+
const pack = await tarTools.getPackStream();
|
|
305
|
+
|
|
306
|
+
// Add files to a pack stream
|
|
307
|
+
await tarTools.addFileToPack(pack, {
|
|
308
|
+
fileName: 'file.txt', // Name in archive
|
|
309
|
+
content: 'Hello World', // String, Buffer, Readable, SmartFile, or StreamFile
|
|
310
|
+
byteLength?: number, // Optional: specify size for streams
|
|
311
|
+
filePath?: string // Optional: path to file on disk
|
|
241
312
|
});
|
|
313
|
+
|
|
314
|
+
// Pack an entire directory
|
|
315
|
+
const pack = await tarTools.packDirectory('./src');
|
|
316
|
+
|
|
317
|
+
// Get extraction stream
|
|
318
|
+
const extract = tarTools.getDecompressionStream();
|
|
242
319
|
```
|
|
243
320
|
|
|
244
|
-
|
|
321
|
+
### ZipTools Class
|
|
245
322
|
|
|
246
|
-
|
|
323
|
+
ZIP-specific operations.
|
|
247
324
|
|
|
248
|
-
|
|
325
|
+
```typescript
|
|
326
|
+
import { ZipTools } from '@push.rocks/smartarchive';
|
|
249
327
|
|
|
250
|
-
|
|
251
|
-
- `SmartArchive.fromArchiveFile(path: string)` - Create from file
|
|
252
|
-
- `SmartArchive.fromArchiveStream(stream: NodeJS.ReadableStream)` - Create from stream
|
|
328
|
+
const zipTools = new ZipTools();
|
|
253
329
|
|
|
254
|
-
|
|
330
|
+
// Get compression stream (for creating ZIP)
|
|
331
|
+
const compressor = zipTools.getCompressionStream();
|
|
332
|
+
|
|
333
|
+
// Get decompression stream (for extracting ZIP)
|
|
334
|
+
const decompressor = zipTools.getDecompressionStream();
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### GzipTools Class
|
|
255
338
|
|
|
256
|
-
|
|
257
|
-
- `exportToStreamOfStreamFiles()` - Get a stream of file streams
|
|
258
|
-
- `exportToTarGzStream()` - Export as TAR.GZ stream
|
|
259
|
-
- `getArchiveStream()` - Get the raw archive stream
|
|
339
|
+
GZIP compression/decompression streams.
|
|
260
340
|
|
|
261
|
-
|
|
341
|
+
```typescript
|
|
342
|
+
import { GzipTools } from '@push.rocks/smartarchive';
|
|
343
|
+
|
|
344
|
+
const gzipTools = new GzipTools();
|
|
262
345
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
- `zipTools` - ZIP-specific operations
|
|
266
|
-
- `gzipTools` - GZIP-specific operations
|
|
267
|
-
- `bzip2Tools` - BZIP2-specific operations
|
|
346
|
+
// Get compression stream
|
|
347
|
+
const compressor = gzipTools.getCompressionStream();
|
|
268
348
|
|
|
269
|
-
|
|
349
|
+
// Get decompression stream
|
|
350
|
+
const decompressor = gzipTools.getDecompressionStream();
|
|
351
|
+
```
|
|
270
352
|
|
|
271
|
-
|
|
353
|
+
## Supported Formats 📋
|
|
272
354
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
355
|
+
| Format | Extension(s) | Extract | Create |
|
|
356
|
+
|--------|--------------|---------|--------|
|
|
357
|
+
| TAR | `.tar` | ✅ | ✅ |
|
|
358
|
+
| TAR.GZ / TGZ | `.tar.gz`, `.tgz` | ✅ | ⚠️ |
|
|
359
|
+
| ZIP | `.zip` | ✅ | ⚠️ |
|
|
360
|
+
| GZIP | `.gz` | ✅ | ✅ |
|
|
361
|
+
| BZIP2 | `.bz2` | ✅ | ❌ |
|
|
362
|
+
|
|
363
|
+
✅ Full support | ⚠️ Partial/basic support | ❌ Not supported
|
|
277
364
|
|
|
278
365
|
## Performance Tips 🏎️
|
|
279
366
|
|
|
280
|
-
1. **Use streaming for large files**
|
|
281
|
-
2. **
|
|
282
|
-
3. **
|
|
283
|
-
4. **
|
|
367
|
+
1. **Use streaming for large files** – Avoid loading entire archives into memory with `exportToStreamOfStreamFiles()`
|
|
368
|
+
2. **Provide byte lengths when known** – When adding streams to TAR, provide `byteLength` for better performance
|
|
369
|
+
3. **Process files as they stream** – Don't collect all files into an array unless necessary
|
|
370
|
+
4. **Choose the right format** – TAR.GZ for Unix/compression, ZIP for cross-platform compatibility
|
|
284
371
|
|
|
285
372
|
## Error Handling 🛡️
|
|
286
373
|
|
|
@@ -295,6 +382,8 @@ try {
|
|
|
295
382
|
console.error('Archive file not found');
|
|
296
383
|
} else if (error.code === 'EACCES') {
|
|
297
384
|
console.error('Permission denied');
|
|
385
|
+
} else if (error.message.includes('fetch')) {
|
|
386
|
+
console.error('Network error downloading archive');
|
|
298
387
|
} else {
|
|
299
388
|
console.error('Archive extraction failed:', error.message);
|
|
300
389
|
}
|
|
@@ -303,35 +392,57 @@ try {
|
|
|
303
392
|
|
|
304
393
|
## Real-World Use Cases 🌍
|
|
305
394
|
|
|
306
|
-
###
|
|
307
|
-
```typescript
|
|
308
|
-
// Automated backup extraction
|
|
309
|
-
const backup = await SmartArchive.fromArchiveFile('./backup.tar.gz');
|
|
310
|
-
await backup.exportToFs('/restore/location');
|
|
311
|
-
```
|
|
395
|
+
### CI/CD: Download & Extract Build Artifacts
|
|
312
396
|
|
|
313
|
-
### CI/CD Pipeline
|
|
314
397
|
```typescript
|
|
315
|
-
// Download and extract build artifacts
|
|
316
398
|
const artifacts = await SmartArchive.fromArchiveUrl(
|
|
317
399
|
`${CI_SERVER}/artifacts/build-${BUILD_ID}.zip`
|
|
318
400
|
);
|
|
319
401
|
await artifacts.exportToFs('./dist');
|
|
320
402
|
```
|
|
321
403
|
|
|
322
|
-
###
|
|
404
|
+
### Backup System: Restore from Archive
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
const backup = await SmartArchive.fromArchiveFile('./backup-2024.tar.gz');
|
|
408
|
+
await backup.exportToFs('/restore/location');
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### NPM Package Inspection
|
|
412
|
+
|
|
413
|
+
```typescript
|
|
414
|
+
const pkg = await SmartArchive.fromArchiveUrl(
|
|
415
|
+
'https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz'
|
|
416
|
+
);
|
|
417
|
+
const files = await pkg.exportToStreamOfStreamFiles();
|
|
418
|
+
|
|
419
|
+
files.on('data', async (file) => {
|
|
420
|
+
if (file.relativeFilePath.includes('package.json')) {
|
|
421
|
+
const stream = await file.createReadStream();
|
|
422
|
+
// Read and analyze package.json
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Data Pipeline: Process Compressed Datasets
|
|
428
|
+
|
|
323
429
|
```typescript
|
|
324
|
-
// Process compressed datasets
|
|
325
430
|
const dataset = await SmartArchive.fromArchiveUrl(
|
|
326
|
-
'https://data.source/dataset.tar.
|
|
431
|
+
'https://data.source/dataset.tar.gz'
|
|
327
432
|
);
|
|
433
|
+
|
|
328
434
|
const files = await dataset.exportToStreamOfStreamFiles();
|
|
329
|
-
|
|
435
|
+
files.on('data', async (file) => {
|
|
436
|
+
if (file.relativeFilePath.endsWith('.csv')) {
|
|
437
|
+
const stream = await file.createReadStream();
|
|
438
|
+
// Stream CSV processing
|
|
439
|
+
}
|
|
440
|
+
});
|
|
330
441
|
```
|
|
331
442
|
|
|
332
443
|
## License and Legal Information
|
|
333
444
|
|
|
334
|
-
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
|
445
|
+
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
|
335
446
|
|
|
336
447
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
|
337
448
|
|
|
@@ -341,9 +452,9 @@ This project is owned and maintained by Task Venture Capital GmbH. The names and
|
|
|
341
452
|
|
|
342
453
|
### Company Information
|
|
343
454
|
|
|
344
|
-
Task Venture Capital GmbH
|
|
455
|
+
Task Venture Capital GmbH
|
|
345
456
|
Registered at District court Bremen HRB 35230 HB, Germany
|
|
346
457
|
|
|
347
458
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
|
348
459
|
|
|
349
|
-
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
|
460
|
+
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
package/ts/00_commitinfo_data.ts
CHANGED
package/ts/bzip2/bititerator.ts
CHANGED
|
@@ -1,44 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { IBitReader } from '../interfaces.js';
|
|
2
|
+
|
|
3
|
+
const BITMASK = [0, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff] as const;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a bit reader function for BZIP2 decompression.
|
|
7
|
+
* Takes a buffer iterator as input and returns a function that reads bits.
|
|
8
|
+
*/
|
|
9
|
+
export function bitIterator(nextBuffer: () => Buffer): IBitReader {
|
|
10
|
+
let bit = 0;
|
|
11
|
+
let byte = 0;
|
|
12
|
+
let bytes = nextBuffer();
|
|
13
|
+
let _bytesRead = 0;
|
|
14
|
+
|
|
15
|
+
const reader = function (n: number | null): number | void {
|
|
16
|
+
if (n === null && bit !== 0) {
|
|
11
17
|
// align to byte boundary
|
|
12
18
|
bit = 0;
|
|
13
19
|
byte++;
|
|
14
20
|
return;
|
|
15
21
|
}
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
|
|
23
|
+
let result = 0;
|
|
24
|
+
let remaining = n as number;
|
|
25
|
+
|
|
26
|
+
while (remaining > 0) {
|
|
18
27
|
if (byte >= bytes.length) {
|
|
19
28
|
byte = 0;
|
|
20
29
|
bytes = nextBuffer();
|
|
21
30
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
|
|
32
|
+
const left = 8 - bit;
|
|
33
|
+
|
|
34
|
+
if (bit === 0 && remaining > 0) {
|
|
35
|
+
_bytesRead++;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (remaining >= left) {
|
|
27
39
|
result <<= left;
|
|
28
40
|
result |= BITMASK[left] & bytes[byte++];
|
|
29
41
|
bit = 0;
|
|
30
|
-
|
|
42
|
+
remaining -= left;
|
|
31
43
|
} else {
|
|
32
|
-
result <<=
|
|
33
|
-
result |=
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
n = 0;
|
|
44
|
+
result <<= remaining;
|
|
45
|
+
result |= (bytes[byte] & (BITMASK[remaining] << (8 - remaining - bit))) >> (8 - remaining - bit);
|
|
46
|
+
bit += remaining;
|
|
47
|
+
remaining = 0;
|
|
37
48
|
}
|
|
38
49
|
}
|
|
50
|
+
|
|
39
51
|
return result;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
} as IBitReader;
|
|
53
|
+
|
|
54
|
+
Object.defineProperty(reader, 'bytesRead', {
|
|
55
|
+
get: () => _bytesRead,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return reader;
|
|
44
60
|
}
|