@push.rocks/smartarchive 5.0.0 → 5.1.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 +2 -2
- package/dist_ts/classes.archiveanalyzer.d.ts +1 -1
- package/dist_ts/classes.archiveanalyzer.js +34 -4
- package/dist_ts/classes.smartarchive.d.ts +151 -54
- package/dist_ts/classes.smartarchive.js +484 -234
- package/dist_ts/classes.tartools.d.ts +9 -33
- package/dist_ts/classes.tartools.js +18 -153
- package/dist_ts/index.d.ts +2 -6
- package/dist_ts/index.js +7 -11
- package/dist_ts/paths.js +1 -1
- package/dist_ts/plugins.d.ts +2 -9
- package/dist_ts/plugins.js +6 -13
- package/npmextra.json +13 -7
- package/package.json +23 -14
- package/readme.hints.md +69 -23
- package/readme.md +360 -274
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.archiveanalyzer.ts +33 -5
- package/ts/classes.smartarchive.ts +546 -256
- package/ts/classes.tartools.ts +20 -177
- package/ts/index.ts +7 -11
- package/ts/plugins.ts +5 -17
- package/{ts → ts_shared}/bzip2/bititerator.ts +1 -1
- package/{ts → ts_shared}/bzip2/bzip2.ts +2 -2
- package/{ts → ts_shared}/bzip2/index.ts +6 -6
- package/ts_shared/classes.bzip2tools.ts +14 -0
- package/ts_shared/classes.gziptools.ts +42 -0
- package/ts_shared/classes.tartools.ts +89 -0
- package/ts_shared/classes.ziptools.ts +107 -0
- package/ts_shared/index.ts +17 -0
- package/{ts → ts_shared}/interfaces.ts +23 -7
- package/ts_shared/plugins.ts +22 -0
- package/ts_web/00_commitinfo_data.ts +8 -0
- package/ts_web/index.ts +4 -0
- package/ts_web/plugins.ts +3 -0
- package/dist_ts/bzip2/bititerator.d.ts +0 -6
- package/dist_ts/bzip2/bititerator.js +0 -50
- package/dist_ts/bzip2/bzip2.d.ts +0 -29
- package/dist_ts/bzip2/bzip2.js +0 -398
- package/dist_ts/bzip2/index.d.ts +0 -5
- package/dist_ts/bzip2/index.js +0 -92
- package/dist_ts/classes.bzip2tools.d.ts +0 -7
- package/dist_ts/classes.bzip2tools.js +0 -11
- package/dist_ts/classes.gziptools.d.ts +0 -49
- package/dist_ts/classes.gziptools.js +0 -125
- package/dist_ts/classes.ziptools.d.ts +0 -56
- package/dist_ts/classes.ziptools.js +0 -185
- package/dist_ts/errors.d.ts +0 -44
- package/dist_ts/errors.js +0 -62
- package/dist_ts/interfaces.d.ts +0 -115
- package/dist_ts/interfaces.js +0 -2
- package/dist_ts/smartarchive.classes.smartarchive.d.ts +0 -34
- package/dist_ts/smartarchive.classes.smartarchive.js +0 -116
- package/dist_ts/smartarchive.paths.d.ts +0 -2
- package/dist_ts/smartarchive.paths.js +0 -4
- package/dist_ts/smartarchive.plugins.d.ts +0 -14
- package/dist_ts/smartarchive.plugins.js +0 -19
- package/ts/classes.bzip2tools.ts +0 -16
- package/ts/classes.gziptools.ts +0 -143
- package/ts/classes.ziptools.ts +0 -209
- /package/{ts → ts_shared}/errors.ts +0 -0
package/ts/classes.ziptools.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import * as plugins from './plugins.js';
|
|
2
|
-
import type { IArchiveEntry, TCompressionLevel } from './interfaces.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Transform stream for ZIP decompression using fflate
|
|
6
|
-
* Emits StreamFile objects for each file in the archive
|
|
7
|
-
*/
|
|
8
|
-
export class ZipDecompressionTransform extends plugins.smartstream.SmartDuplex<Buffer, plugins.smartfile.StreamFile> {
|
|
9
|
-
private streamtools!: plugins.smartstream.IStreamTools;
|
|
10
|
-
private unzipper = new plugins.fflate.Unzip(async (fileArg) => {
|
|
11
|
-
let resultBuffer: Buffer;
|
|
12
|
-
fileArg.ondata = async (_flateError, dat, final) => {
|
|
13
|
-
resultBuffer
|
|
14
|
-
? (resultBuffer = Buffer.concat([resultBuffer, Buffer.from(dat)]))
|
|
15
|
-
: (resultBuffer = Buffer.from(dat));
|
|
16
|
-
if (final) {
|
|
17
|
-
const streamFile = plugins.smartfile.StreamFile.fromBuffer(resultBuffer);
|
|
18
|
-
streamFile.relativeFilePath = fileArg.name;
|
|
19
|
-
this.streamtools.push(streamFile);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
fileArg.start();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
super({
|
|
27
|
-
objectMode: true,
|
|
28
|
-
writeFunction: async (chunkArg, streamtoolsArg) => {
|
|
29
|
-
this.streamtools ? null : (this.streamtools = streamtoolsArg);
|
|
30
|
-
this.unzipper.push(
|
|
31
|
-
Buffer.isBuffer(chunkArg) ? chunkArg : Buffer.from(chunkArg as unknown as ArrayBuffer),
|
|
32
|
-
false
|
|
33
|
-
);
|
|
34
|
-
return null;
|
|
35
|
-
},
|
|
36
|
-
finalFunction: async () => {
|
|
37
|
-
this.unzipper.push(Buffer.from(''), true);
|
|
38
|
-
await plugins.smartdelay.delayFor(0);
|
|
39
|
-
await this.streamtools.push(null);
|
|
40
|
-
return null;
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
this.unzipper.register(plugins.fflate.UnzipInflate);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Streaming ZIP compression using fflate
|
|
49
|
-
* Allows adding multiple entries before finalizing
|
|
50
|
-
*/
|
|
51
|
-
export class ZipCompressionStream extends plugins.stream.Duplex {
|
|
52
|
-
private files: Map<string, { data: Uint8Array; options?: plugins.fflate.ZipOptions }> = new Map();
|
|
53
|
-
private finalized = false;
|
|
54
|
-
|
|
55
|
-
constructor() {
|
|
56
|
-
super();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Add a file entry to the ZIP archive
|
|
61
|
-
*/
|
|
62
|
-
public async addEntry(
|
|
63
|
-
fileName: string,
|
|
64
|
-
content: Buffer | plugins.stream.Readable,
|
|
65
|
-
options?: { compressionLevel?: TCompressionLevel }
|
|
66
|
-
): Promise<void> {
|
|
67
|
-
if (this.finalized) {
|
|
68
|
-
throw new Error('Cannot add entries to a finalized ZIP archive');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let data: Buffer;
|
|
72
|
-
if (Buffer.isBuffer(content)) {
|
|
73
|
-
data = content;
|
|
74
|
-
} else {
|
|
75
|
-
// Collect stream to buffer
|
|
76
|
-
const chunks: Buffer[] = [];
|
|
77
|
-
for await (const chunk of content) {
|
|
78
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
79
|
-
}
|
|
80
|
-
data = Buffer.concat(chunks);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
this.files.set(fileName, {
|
|
84
|
-
data: new Uint8Array(data),
|
|
85
|
-
options: options?.compressionLevel !== undefined ? { level: options.compressionLevel } : undefined,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Finalize the ZIP archive and emit the compressed data
|
|
91
|
-
*/
|
|
92
|
-
public async finalize(): Promise<void> {
|
|
93
|
-
if (this.finalized) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
this.finalized = true;
|
|
97
|
-
|
|
98
|
-
const filesObj: plugins.fflate.Zippable = {};
|
|
99
|
-
for (const [name, { data, options }] of this.files) {
|
|
100
|
-
filesObj[name] = options ? [data, options] : data;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return new Promise((resolve, reject) => {
|
|
104
|
-
plugins.fflate.zip(filesObj, (err, result) => {
|
|
105
|
-
if (err) {
|
|
106
|
-
reject(err);
|
|
107
|
-
} else {
|
|
108
|
-
this.push(Buffer.from(result));
|
|
109
|
-
this.push(null);
|
|
110
|
-
resolve();
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
_read(): void {
|
|
117
|
-
// No-op: data is pushed when finalize() is called
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
_write(
|
|
121
|
-
_chunk: Buffer,
|
|
122
|
-
_encoding: BufferEncoding,
|
|
123
|
-
callback: (error?: Error | null) => void
|
|
124
|
-
): void {
|
|
125
|
-
// Not used for ZIP creation - use addEntry() instead
|
|
126
|
-
callback(new Error('Use addEntry() to add files to the ZIP archive'));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* ZIP compression and decompression utilities
|
|
132
|
-
*/
|
|
133
|
-
export class ZipTools {
|
|
134
|
-
/**
|
|
135
|
-
* Get a streaming compression object for creating ZIP archives
|
|
136
|
-
*/
|
|
137
|
-
public getCompressionStream(): ZipCompressionStream {
|
|
138
|
-
return new ZipCompressionStream();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Get a streaming decompression transform for extracting ZIP archives
|
|
143
|
-
*/
|
|
144
|
-
public getDecompressionStream(): ZipDecompressionTransform {
|
|
145
|
-
return new ZipDecompressionTransform();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Create a ZIP archive from an array of entries
|
|
150
|
-
*/
|
|
151
|
-
public async createZip(entries: IArchiveEntry[], compressionLevel?: TCompressionLevel): Promise<Buffer> {
|
|
152
|
-
const filesObj: plugins.fflate.Zippable = {};
|
|
153
|
-
|
|
154
|
-
for (const entry of entries) {
|
|
155
|
-
let data: Uint8Array;
|
|
156
|
-
|
|
157
|
-
if (typeof entry.content === 'string') {
|
|
158
|
-
data = new TextEncoder().encode(entry.content);
|
|
159
|
-
} else if (Buffer.isBuffer(entry.content)) {
|
|
160
|
-
data = new Uint8Array(entry.content);
|
|
161
|
-
} else if (entry.content instanceof plugins.smartfile.SmartFile) {
|
|
162
|
-
data = new Uint8Array(entry.content.contents);
|
|
163
|
-
} else if (entry.content instanceof plugins.smartfile.StreamFile) {
|
|
164
|
-
const buffer = await entry.content.getContentAsBuffer();
|
|
165
|
-
data = new Uint8Array(buffer);
|
|
166
|
-
} else {
|
|
167
|
-
// Readable stream
|
|
168
|
-
const chunks: Buffer[] = [];
|
|
169
|
-
for await (const chunk of entry.content as plugins.stream.Readable) {
|
|
170
|
-
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
171
|
-
}
|
|
172
|
-
data = new Uint8Array(Buffer.concat(chunks));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (compressionLevel !== undefined) {
|
|
176
|
-
filesObj[entry.archivePath] = [data, { level: compressionLevel }];
|
|
177
|
-
} else {
|
|
178
|
-
filesObj[entry.archivePath] = data;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return new Promise((resolve, reject) => {
|
|
183
|
-
plugins.fflate.zip(filesObj, (err, result) => {
|
|
184
|
-
if (err) reject(err);
|
|
185
|
-
else resolve(Buffer.from(result));
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Extract a ZIP buffer to an array of entries
|
|
192
|
-
*/
|
|
193
|
-
public async extractZip(data: Buffer): Promise<Array<{ path: string; content: Buffer }>> {
|
|
194
|
-
return new Promise((resolve, reject) => {
|
|
195
|
-
plugins.fflate.unzip(data, (err, result) => {
|
|
196
|
-
if (err) {
|
|
197
|
-
reject(err);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const entries: Array<{ path: string; content: Buffer }> = [];
|
|
202
|
-
for (const [path, content] of Object.entries(result)) {
|
|
203
|
-
entries.push({ path, content: Buffer.from(content) });
|
|
204
|
-
}
|
|
205
|
-
resolve(entries);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
File without changes
|