@push.rocks/smartarchive 4.2.4 → 5.0.1
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 +43 -6
- package/dist_ts/classes.gziptools.js +76 -24
- package/dist_ts/classes.smartarchive.d.ts +198 -16
- package/dist_ts/classes.smartarchive.js +652 -79
- package/dist_ts/classes.tartools.d.ts +31 -4
- package/dist_ts/classes.tartools.js +93 -32
- package/dist_ts/classes.ziptools.d.ts +47 -12
- package/dist_ts/classes.ziptools.js +128 -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 +119 -0
- package/dist_ts/interfaces.js +2 -0
- package/package.json +1 -1
- package/readme.hints.md +69 -23
- package/readme.md +360 -274
- 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 +91 -33
- package/ts/classes.smartarchive.ts +765 -140
- package/ts/classes.tartools.ts +124 -52
- package/ts/classes.ziptools.ts +147 -34
- package/ts/errors.ts +70 -0
- package/ts/index.ts +11 -0
- package/ts/interfaces.ts +136 -0
|
@@ -1,32 +1,214 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
|
+
import type { IArchiveEntryInfo, IArchiveInfo, TArchiveFormat, TCompressionLevel, TEntryFilter } from './interfaces.js';
|
|
2
3
|
import { Bzip2Tools } from './classes.bzip2tools.js';
|
|
3
4
|
import { GzipTools } from './classes.gziptools.js';
|
|
4
5
|
import { TarTools } from './classes.tartools.js';
|
|
5
6
|
import { ZipTools } from './classes.ziptools.js';
|
|
6
7
|
import { ArchiveAnalyzer } from './classes.archiveanalyzer.js';
|
|
8
|
+
/**
|
|
9
|
+
* Main class for archive manipulation with fluent API
|
|
10
|
+
* Supports TAR, ZIP, GZIP, and BZIP2 formats
|
|
11
|
+
*
|
|
12
|
+
* @example Extraction from URL
|
|
13
|
+
* ```typescript
|
|
14
|
+
* await SmartArchive.create()
|
|
15
|
+
* .url('https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz')
|
|
16
|
+
* .stripComponents(1)
|
|
17
|
+
* .extract('./node_modules/lodash');
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example Creation with thenable
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const archive = await SmartArchive.create()
|
|
23
|
+
* .format('tar.gz')
|
|
24
|
+
* .compression(9)
|
|
25
|
+
* .entry('config.json', JSON.stringify(config))
|
|
26
|
+
* .directory('./src');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
7
29
|
export declare class SmartArchive {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Create a new SmartArchive instance for fluent configuration
|
|
32
|
+
*/
|
|
33
|
+
static create(): SmartArchive;
|
|
11
34
|
tarTools: TarTools;
|
|
12
35
|
zipTools: ZipTools;
|
|
13
36
|
gzipTools: GzipTools;
|
|
14
37
|
bzip2Tools: Bzip2Tools;
|
|
15
38
|
archiveAnalyzer: ArchiveAnalyzer;
|
|
16
|
-
sourceUrl
|
|
17
|
-
sourceFilePath
|
|
18
|
-
sourceStream
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
39
|
+
private sourceUrl?;
|
|
40
|
+
private sourceFilePath?;
|
|
41
|
+
private sourceStream?;
|
|
42
|
+
private archiveBuffer?;
|
|
43
|
+
private creationFormat?;
|
|
44
|
+
private _compressionLevel;
|
|
45
|
+
private pendingEntries;
|
|
46
|
+
private pendingDirectories;
|
|
47
|
+
private _mode;
|
|
48
|
+
private _filters;
|
|
49
|
+
private _excludePatterns;
|
|
50
|
+
private _includePatterns;
|
|
51
|
+
private _stripComponents;
|
|
52
|
+
private _overwrite;
|
|
53
|
+
private _fileName?;
|
|
24
54
|
constructor();
|
|
25
55
|
/**
|
|
26
|
-
*
|
|
56
|
+
* Load archive from URL
|
|
57
|
+
*/
|
|
58
|
+
url(urlArg: string): this;
|
|
59
|
+
/**
|
|
60
|
+
* Load archive from file path
|
|
61
|
+
*/
|
|
62
|
+
file(pathArg: string): this;
|
|
63
|
+
/**
|
|
64
|
+
* Load archive from readable stream
|
|
65
|
+
*/
|
|
66
|
+
stream(streamArg: plugins.stream.Readable | plugins.stream.Duplex | plugins.stream.Transform): this;
|
|
67
|
+
/**
|
|
68
|
+
* Load archive from buffer
|
|
69
|
+
*/
|
|
70
|
+
buffer(bufferArg: Buffer): this;
|
|
71
|
+
/**
|
|
72
|
+
* Set output format for archive creation
|
|
73
|
+
*/
|
|
74
|
+
format(fmt: TArchiveFormat): this;
|
|
75
|
+
/**
|
|
76
|
+
* Set compression level (0-9)
|
|
77
|
+
*/
|
|
78
|
+
compression(level: TCompressionLevel): this;
|
|
79
|
+
/**
|
|
80
|
+
* Add a single file entry to the archive
|
|
81
|
+
*/
|
|
82
|
+
entry(archivePath: string, content: string | Buffer): this;
|
|
83
|
+
/**
|
|
84
|
+
* Add multiple entries to the archive
|
|
85
|
+
*/
|
|
86
|
+
entries(entriesArg: Array<{
|
|
87
|
+
archivePath: string;
|
|
88
|
+
content: string | Buffer;
|
|
89
|
+
}>): this;
|
|
90
|
+
/**
|
|
91
|
+
* Add an entire directory to the archive (queued, resolved at build time)
|
|
92
|
+
*/
|
|
93
|
+
directory(sourcePath: string, archiveBase?: string): this;
|
|
94
|
+
/**
|
|
95
|
+
* Add a SmartFile to the archive
|
|
96
|
+
*/
|
|
97
|
+
addSmartFile(fileArg: plugins.smartfile.SmartFile, archivePath?: string): this;
|
|
98
|
+
/**
|
|
99
|
+
* Add a StreamFile to the archive
|
|
100
|
+
*/
|
|
101
|
+
addStreamFile(fileArg: plugins.smartfile.StreamFile, archivePath?: string): this;
|
|
102
|
+
/**
|
|
103
|
+
* Filter entries by predicate function
|
|
104
|
+
*/
|
|
105
|
+
filter(predicate: TEntryFilter): this;
|
|
106
|
+
/**
|
|
107
|
+
* Include only entries matching the pattern
|
|
108
|
+
*/
|
|
109
|
+
include(pattern: string | RegExp): this;
|
|
110
|
+
/**
|
|
111
|
+
* Exclude entries matching the pattern
|
|
112
|
+
*/
|
|
113
|
+
exclude(pattern: string | RegExp): this;
|
|
114
|
+
/**
|
|
115
|
+
* Strip N leading path components from extracted files
|
|
116
|
+
*/
|
|
117
|
+
stripComponents(n: number): this;
|
|
118
|
+
/**
|
|
119
|
+
* Overwrite existing files during extraction
|
|
120
|
+
*/
|
|
121
|
+
overwrite(value?: boolean): this;
|
|
122
|
+
/**
|
|
123
|
+
* Set output filename for single-file archives (gz, bz2)
|
|
124
|
+
*/
|
|
125
|
+
fileName(name: string): this;
|
|
126
|
+
/**
|
|
127
|
+
* Extract archive to filesystem directory
|
|
128
|
+
*/
|
|
129
|
+
extract(targetDir: string): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Extract archive to a stream of StreamFile objects
|
|
132
|
+
*/
|
|
133
|
+
toStreamFiles(): Promise<plugins.smartstream.StreamIntake<plugins.smartfile.StreamFile>>;
|
|
134
|
+
/**
|
|
135
|
+
* Extract archive to an array of SmartFile objects (in-memory)
|
|
136
|
+
*/
|
|
137
|
+
toSmartFiles(): Promise<plugins.smartfile.SmartFile[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Extract a single file from the archive by path
|
|
140
|
+
*/
|
|
141
|
+
extractFile(filePath: string): Promise<plugins.smartfile.SmartFile | null>;
|
|
142
|
+
/**
|
|
143
|
+
* Build and finalize the archive, returning this instance
|
|
144
|
+
*/
|
|
145
|
+
build(): Promise<SmartArchive>;
|
|
146
|
+
/**
|
|
147
|
+
* Internal build implementation (avoids thenable recursion)
|
|
148
|
+
*/
|
|
149
|
+
private doBuild;
|
|
150
|
+
/**
|
|
151
|
+
* Build archive and return as Buffer
|
|
152
|
+
*/
|
|
153
|
+
toBuffer(): Promise<Buffer>;
|
|
154
|
+
/**
|
|
155
|
+
* Build archive and write to file
|
|
156
|
+
*/
|
|
157
|
+
toFile(filePath: string): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Get archive as a readable stream
|
|
160
|
+
*/
|
|
161
|
+
toStream(): Promise<plugins.stream.Readable>;
|
|
162
|
+
/**
|
|
163
|
+
* Analyze the archive and return metadata
|
|
164
|
+
*/
|
|
165
|
+
analyze(): Promise<IArchiveInfo>;
|
|
166
|
+
/**
|
|
167
|
+
* List all entries in the archive
|
|
168
|
+
*/
|
|
169
|
+
list(): Promise<IArchiveEntryInfo[]>;
|
|
170
|
+
/**
|
|
171
|
+
* Check if a specific file exists in the archive
|
|
172
|
+
*/
|
|
173
|
+
hasFile(filePath: string): Promise<boolean>;
|
|
174
|
+
/**
|
|
175
|
+
* Ensure we're not in create mode when calling extraction methods
|
|
176
|
+
*/
|
|
177
|
+
private ensureNotInCreateMode;
|
|
178
|
+
/**
|
|
179
|
+
* Ensure we're not in extract mode when calling creation methods
|
|
180
|
+
*/
|
|
181
|
+
private ensureNotInExtractMode;
|
|
182
|
+
/**
|
|
183
|
+
* Ensure an extraction source is configured
|
|
184
|
+
*/
|
|
185
|
+
private ensureExtractionSource;
|
|
186
|
+
/**
|
|
187
|
+
* Ensure a format is configured for creation
|
|
188
|
+
*/
|
|
189
|
+
private ensureCreationFormat;
|
|
190
|
+
/**
|
|
191
|
+
* Get the source stream
|
|
192
|
+
*/
|
|
193
|
+
private getSourceStream;
|
|
194
|
+
/**
|
|
195
|
+
* Build a combined filter function from all configured filters
|
|
196
|
+
*/
|
|
197
|
+
private buildFilterFunction;
|
|
198
|
+
/**
|
|
199
|
+
* Resolve pending directories to entries
|
|
200
|
+
*/
|
|
201
|
+
private resolveDirectories;
|
|
202
|
+
/**
|
|
203
|
+
* Get entries filtered by include/exclude patterns
|
|
204
|
+
*/
|
|
205
|
+
private getFilteredEntries;
|
|
206
|
+
/**
|
|
207
|
+
* Convert a stream to buffer
|
|
208
|
+
*/
|
|
209
|
+
private streamToBuffer;
|
|
210
|
+
/**
|
|
211
|
+
* Read first chunk from stream
|
|
27
212
|
*/
|
|
28
|
-
|
|
29
|
-
exportToTarGzStream(): Promise<void>;
|
|
30
|
-
exportToFs(targetDir: string, fileNameArg?: string): Promise<void>;
|
|
31
|
-
exportToStreamOfStreamFiles(): Promise<plugins.smartstream.StreamIntake<plugins.smartfile.StreamFile>>;
|
|
213
|
+
private readFirstChunk;
|
|
32
214
|
}
|