@push.rocks/smartarchive 4.0.32 → 4.0.33

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.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartarchive',
6
- version: '4.0.32',
6
+ version: '4.0.33',
7
7
  description: 'A library for working with archive files, providing utilities for compressing and decompressing data.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSwwQkFBMEI7SUFDaEMsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLHVHQUF1RztDQUNySCxDQUFBIn0=
package/npmextra.json CHANGED
@@ -18,8 +18,12 @@
18
18
  "decompression",
19
19
  "zip",
20
20
  "tar",
21
+ "gzip",
21
22
  "bzip2",
22
- "gzip"
23
+ "file extraction",
24
+ "file creation",
25
+ "data analysis",
26
+ "file stream"
23
27
  ]
24
28
  }
25
29
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartarchive",
3
- "version": "4.0.32",
3
+ "version": "4.0.33",
4
4
  "description": "A library for working with archive files, providing utilities for compressing and decompressing data.",
5
5
  "main": "dist_ts/index.js",
6
6
  "typings": "dist_ts/index.d.ts",
@@ -59,8 +59,12 @@
59
59
  "decompression",
60
60
  "zip",
61
61
  "tar",
62
+ "gzip",
62
63
  "bzip2",
63
- "gzip"
64
+ "file extraction",
65
+ "file creation",
66
+ "data analysis",
67
+ "file stream"
64
68
  ],
65
69
  "scripts": {
66
70
  "test": "(tstest test/ --web)",
package/readme.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # @push.rocks/smartarchive
2
- work with archives
2
+
3
+ `@push.rocks/smartarchive` is a powerful library designed for managing archive files. It provides utilities for compressing and decompressing data in various formats such as zip, tar, gzip, and bzip2. This library aims to simplify the process of handling archive files, making it an ideal choice for projects that require manipulation of archived data.
3
4
 
4
5
  ## Install
5
6
 
6
- To install `@push.rocks/smartarchive`, you need to use npm or yarn. Run either of the following commands in your project directory:
7
+ To install `@push.rocks/smartarchive`, you can either use npm or yarn. Run one of the following commands in your project directory:
7
8
 
8
9
  ```shell
9
10
  npm install @push.rocks/smartarchive --save
@@ -18,10 +19,9 @@ yarn add @push.rocks/smartarchive
18
19
  This will add `@push.rocks/smartarchive` to your project's dependencies.
19
20
 
20
21
  ## Usage
22
+ `@push.rocks/smartarchive` provides an easy-to-use API for extracting, creating, and analyzing archive files. Below, we'll cover how to get started and explore various features of the module.
21
23
 
22
- `@push.rocks/smartarchive` is a powerful module designed to simplify the process of working with archive files such as zip, tar, gzip, and more. It provides an easy-to-use API for extracting, creating, and analyzing archives, making it an ideal choice for projects that require manipulation of archive files.
23
-
24
- ### Getting Started
24
+ ### Importing SmartArchive
25
25
 
26
26
  First, import `SmartArchive` from `@push.rocks/smartarchive` using ESM syntax:
27
27
 
@@ -31,9 +31,11 @@ import { SmartArchive } from '@push.rocks/smartarchive';
31
31
 
32
32
  ### Extracting Archive Files
33
33
 
34
- To extract an archive file, you can use `SmartArchive.fromArchiveUrl`, `SmartArchive.fromArchiveFile`, or `SmartArchive.fromArchiveStream` methods depending on the source of your archive. Here's an example of extracting an archive from a URL:
34
+ You can extract archive files from different sources using `SmartArchive.fromArchiveUrl`, `SmartArchive.fromArchiveFile`, and `SmartArchive.fromArchiveStream`. Here's an example of extracting an archive from a URL:
35
35
 
36
36
  ```typescript
37
+ import { SmartArchive } from '@push.rocks/smartarchive';
38
+
37
39
  async function extractArchiveFromURL() {
38
40
  const url = 'https://example.com/archive.zip';
39
41
  const targetDir = '/path/to/extract';
@@ -43,52 +45,222 @@ async function extractArchiveFromURL() {
43
45
 
44
46
  console.log('Archive extracted successfully.');
45
47
  }
48
+
49
+ extractArchiveFromURL();
46
50
  ```
47
51
 
48
- ### Creating Archive Files
52
+ ### Extracting an Archive from a File
53
+
54
+ Similarly, you can extract an archive from a local file:
55
+
56
+ ```typescript
57
+ import { SmartArchive } from '@push.rocks/smartarchive';
58
+
59
+ async function extractArchiveFromFile() {
60
+ const filePath = '/path/to/archive.zip';
61
+ const targetDir = '/path/to/extract';
62
+
63
+ const archive = await SmartArchive.fromArchiveFile(filePath);
64
+ await archive.exportToFs(targetDir);
65
+
66
+ console.log('Archive extracted successfully.');
67
+ }
68
+
69
+ extractArchiveFromFile();
70
+ ```
71
+
72
+ ### Stream-Based Extraction
73
+
74
+ For larger files, you might prefer a streaming approach to prevent high memory consumption. Here’s an example:
75
+
76
+ ```typescript
77
+ import { SmartArchive } from '@push.rocks/smartarchive';
78
+ import { createReadStream } from 'fs';
79
+
80
+ async function extractArchiveUsingStream() {
81
+ const archiveStream = createReadStream('/path/to/archive.zip');
82
+ const archive = await SmartArchive.fromArchiveStream(archiveStream);
83
+ const extractionStream = await archive.exportToStreamOfStreamFiles();
84
+
85
+ extractionStream.pipe(createWriteStream('/path/to/destination'));
86
+ }
49
87
 
50
- Creating archive files such as zip or tar.gz is straightforward with `smartarchive`. At the moment, you'll prepare the contents programmatically and then compress them. Detailed support for creating archives will be covered in future updates.
88
+ extractArchiveUsingStream();
89
+ ```
51
90
 
52
91
  ### Analyzing Archive Files
53
92
 
54
- Analyzing the content of archives without extracting them can be useful in various scenarios, such as when you need to inspect the archive's content before deciding to extract it. Here's how you might analyze an archive:
93
+ Sometimes, you may need to inspect the contents of an archive before extracting it. The following example shows how to analyze an archive:
55
94
 
56
95
  ```typescript
96
+ import { SmartArchive } from '@push.rocks/smartarchive';
97
+
57
98
  async function analyzeArchive() {
58
- const url = 'https://example.com/archive.zip';
99
+ const filePath = '/path/to/archive.zip';
59
100
 
60
- const archive = await SmartArchive.fromArchiveUrl(url);
101
+ const archive = await SmartArchive.fromArchiveFile(filePath);
61
102
  const analysisResult = await archive.analyzeContent();
62
103
 
63
104
  console.log(analysisResult); // Outputs details about the archive content
64
105
  }
106
+
107
+ analyzeArchive();
65
108
  ```
66
109
 
67
- Note: Replace `analyzeContent` with the appropriate method calls as per your implementation or update, as `smartarchive` provides foundational classes and methods for interaction with archive files but does not directly implement an `analyzeContent` method by default.
110
+ ### Creating Archive Files
111
+
112
+ Creating an archive file is straightforward. Here we demonstrate creating a tar.gz archive:
113
+
114
+ ```typescript
115
+ import { SmartArchive } from '@push.rocks/smartarchive';
116
+
117
+ async function createTarGzArchive() {
118
+ const archive = new SmartArchive();
119
+
120
+ // Add directories and files
121
+ archive.addedDirectories.push('/path/to/directory1');
122
+ archive.addedFiles.push('/path/to/file1.txt');
123
+
124
+ // Export as tar.gz
125
+ const tarGzStream = await archive.exportToTarGzStream();
126
+
127
+ // Save to filesystem or handle as needed
128
+ tarGzStream.pipe(createWriteStream('/path/to/destination.tar.gz'));
129
+ }
130
+
131
+ createTarGzArchive();
132
+ ```
68
133
 
69
134
  ### Stream Operations
70
135
 
71
- `smartarchive` offers streaming operations, allowing you to work with large archives efficiently. Here's an example of using streams to extract an archive:
136
+ Here's an example of using `smartarchive`'s streaming capabilities:
72
137
 
73
138
  ```typescript
74
139
  import { createReadStream, createWriteStream } from 'fs';
140
+ import { SmartArchive } from '@push.rocks/smartarchive';
75
141
 
76
- async function extractArchiveUsingStream() {
142
+ async function extractArchiveUsingStreams() {
77
143
  const archiveStream = createReadStream('/path/to/archive.zip');
78
144
  const archive = await SmartArchive.fromArchiveStream(archiveStream);
79
145
  const extractionStream = await archive.exportToStreamOfStreamFiles();
80
146
 
81
- extractionStream.pipe(createWriteStream('/path/to/destination'));
147
+ extractionStream.pipe(createWriteStream('/path/to/extracted'));
148
+ }
149
+
150
+ extractArchiveUsingStreams();
151
+ ```
152
+
153
+ ### Advanced Decompression Usage
154
+
155
+ `smartarchive` supports multiple compression formats. It also provides detailed control over the decompression processes:
156
+
157
+ - For ZIP files, `ZipTools` handles decompression using the `fflate` library.
158
+ - For TAR files, `TarTools` uses `tar-stream`.
159
+ - For GZIP files, `GzipTools` provides a `CompressGunzipTransform` and `DecompressGunzipTransform`.
160
+ - For BZIP2 files, `Bzip2Tools` utilizes custom streaming decompression.
161
+
162
+ Example: Working with a GZIP-compressed archive:
163
+
164
+ ```typescript
165
+ import { createReadStream, createWriteStream } from 'fs';
166
+ import { SmartArchive } from '@push.rocks/smartarchive';
167
+
168
+ async function decompressGzipArchive() {
169
+ const filePath = '/path/to/archive.gz';
170
+ const targetDir = '/path/to/extract';
171
+
172
+ const archive = await SmartArchive.fromArchiveFile(filePath);
173
+ await archive.exportToFs(targetDir);
174
+
175
+ console.log('GZIP archive decompressed successfully.');
176
+ }
177
+
178
+ decompressGzipArchive();
179
+ ```
180
+
181
+ ### Advancing with Custom Decompression Streams
182
+
183
+ You can inject custom decompression streams where needed:
184
+
185
+ ```typescript
186
+ import { createReadStream, createWriteStream } from 'fs';
187
+ import { SmartArchive, GzipTools } from '@push.rocks/smartarchive';
188
+
189
+ async function customDecompression() {
190
+ const filePath = '/path/to/archive.gz';
191
+ const targetDir = '/path/to/extract';
192
+
193
+ const archive = await SmartArchive.fromArchiveFile(filePath);
194
+ const gzipTools = new GzipTools();
195
+ const decompressionStream = gzipTools.getDecompressionStream();
196
+
197
+ const archiveStream = await archive.getArchiveStream();
198
+ archiveStream.pipe(decompressionStream).pipe(createWriteStream(targetDir));
199
+
200
+ console.log('Custom GZIP decompression successful.');
82
201
  }
202
+
203
+ customDecompression();
83
204
  ```
84
205
 
85
- ### Conclusion
206
+ ### Custom Pack and Unpack Tar
207
+
208
+ When dealing with tar archives, you may need to perform custom packing and unpacking:
209
+
210
+ ```typescript
211
+ import { SmartArchive, TarTools } from '@push.rocks/smartarchive';
212
+ import { createWriteStream } from 'fs';
213
+
214
+ async function customTarOperations() {
215
+ const tarTools = new TarTools();
216
+
217
+ // Packing a directory into a tar stream
218
+ const packStream = await tarTools.packDirectory('/path/to/directory');
219
+ packStream.pipe(createWriteStream('/path/to/archive.tar'));
220
+
221
+ // Extracting files from a tar stream
222
+ const extractStream = tarTools.getDecompressionStream();
223
+ createReadStream('/path/to/archive.tar').pipe(extractStream).on('entry', (header, stream, next) => {
224
+ const writeStream = createWriteStream(`/path/to/extract/${header.name}`);
225
+ stream.pipe(writeStream);
226
+ stream.on('end', next);
227
+ });
228
+ }
229
+
230
+ customTarOperations();
231
+ ```
232
+
233
+ ### Extract and Analyze All-in-One
234
+
235
+ To extract and simultaneously analyze archive content:
236
+
237
+ ```typescript
238
+ import { createReadStream, createWriteStream } from 'fs';
239
+ import { SmartArchive } from '@push.rocks/smartarchive';
240
+
241
+ async function extractAndAnalyze() {
242
+ const filePath = '/path/to/archive.zip';
243
+ const targetDir = '/path/to/extract';
244
+
245
+ const archive = await SmartArchive.fromArchiveFile(filePath);
246
+ const analyzedStream = archive.archiveAnalyzer.getAnalyzedStream();
247
+ const extractionStream = await archive.exportToStreamOfStreamFiles();
248
+
249
+ analyzedStream.pipe(extractionStream).pipe(createWriteStream(targetDir));
250
+
251
+ analyzedStream.on('data', (chunk) => {
252
+ console.log(JSON.stringify(chunk, null, 2));
253
+ });
254
+ }
255
+
256
+ extractAndAnalyze();
257
+ ```
86
258
 
87
- `@push.rocks/smartarchive` simplifies the process of working with various archive formats in JavaScript and TypeScript projects. By providing an easy-to-use API for common archive operations, it enables developers to integrate archive manipulation features into their applications efficiently.
259
+ ### Final Words
88
260
 
89
- Remember, the examples provided here are to give you a starting point. Depending on your specific use case, you may need to adjust these examples to fit your project's requirements. Always refer to the latest documentation for the most current information and methods available in `@push.rocks/smartarchive`.
261
+ These examples demonstrate various use cases for `@push.rocks/smartarchive`. Depending on your specific project requirements, you can adapt these examples to suit your needs. Always refer to the latest documentation for the most current information and methods available in `@push.rocks/smartarchive`.
90
262
 
91
- For more information and API references, check the official [`@push.rocks/smartarchive` GitHub repository](https://github.com/pushrocks/smartarchive).
263
+ For more information and API references, check the official [`@push.rocks/smartarchive` GitHub repository](https://code.foss.global/push.rocks/smartarchive).
92
264
 
93
265
  ## License and Legal Information
94
266
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartarchive',
6
- version: '4.0.32',
6
+ version: '4.0.33',
7
7
  description: 'A library for working with archive files, providing utilities for compressing and decompressing data.'
8
8
  }