@push.rocks/smartarchive 4.0.39 → 4.2.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/bzip2/bititerator.js +7 -6
- package/dist_ts/bzip2/bzip2.js +76 -93
- package/dist_ts/bzip2/index.js +3 -2
- package/dist_ts/classes.archiveanalyzer.d.ts +1 -1
- package/dist_ts/classes.archiveanalyzer.js +2 -2
- package/dist_ts/classes.gziptools.js +2 -3
- package/dist_ts/classes.smartarchive.d.ts +1 -1
- package/dist_ts/classes.smartarchive.js +14 -6
- package/dist_ts/classes.tartools.js +3 -2
- package/dist_ts/classes.ziptools.d.ts +2 -1
- package/dist_ts/classes.ziptools.js +10 -9
- package/dist_ts/plugins.d.ts +1 -1
- package/dist_ts/plugins.js +2 -2
- package/npmextra.json +1 -1
- package/package.json +15 -16
- package/readme.md +239 -172
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/bzip2/bititerator.ts +40 -37
- package/ts/bzip2/bzip2.ts +259 -263
- package/ts/bzip2/index.ts +13 -3
- package/ts/classes.archiveanalyzer.ts +17 -8
- package/ts/classes.bzip2tools.ts +1 -1
- package/ts/classes.gziptools.ts +12 -6
- package/ts/classes.smartarchive.ts +78 -31
- package/ts/classes.tartools.ts +21 -9
- package/ts/classes.ziptools.ts +21 -12
- package/ts/paths.ts +1 -1
- package/ts/plugins.ts +11 -1
|
@@ -5,7 +5,10 @@ export interface IAnalyzedResult {
|
|
|
5
5
|
fileType: plugins.fileType.FileTypeResult;
|
|
6
6
|
isArchive: boolean;
|
|
7
7
|
resultStream: plugins.smartstream.SmartDuplex;
|
|
8
|
-
decompressionStream:
|
|
8
|
+
decompressionStream:
|
|
9
|
+
| plugins.stream.Transform
|
|
10
|
+
| plugins.stream.Duplex
|
|
11
|
+
| plugins.tarStream.Extract;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
export class ArchiveAnalyzer {
|
|
@@ -25,14 +28,15 @@ export class ArchiveAnalyzer {
|
|
|
25
28
|
'application/x-bzip2',
|
|
26
29
|
// Add other archive mime types here
|
|
27
30
|
]);
|
|
28
|
-
|
|
31
|
+
|
|
29
32
|
return archiveMimeTypes.has(mimeType);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
|
|
33
35
|
private async getDecompressionStream(
|
|
34
|
-
mimeTypeArg: plugins.fileType.FileTypeResult['mime']
|
|
35
|
-
):
|
|
36
|
+
mimeTypeArg: plugins.fileType.FileTypeResult['mime'],
|
|
37
|
+
): Promise<
|
|
38
|
+
plugins.stream.Transform | plugins.stream.Duplex | plugins.tarStream.Extract
|
|
39
|
+
> {
|
|
36
40
|
switch (mimeTypeArg) {
|
|
37
41
|
case 'application/gzip':
|
|
38
42
|
return this.smartArchiveRef.gzipTools.getDecompressionStream();
|
|
@@ -51,13 +55,18 @@ export class ArchiveAnalyzer {
|
|
|
51
55
|
public getAnalyzedStream() {
|
|
52
56
|
let firstRun = true;
|
|
53
57
|
const resultStream = plugins.smartstream.createPassThrough();
|
|
54
|
-
const analyzerstream = new plugins.smartstream.SmartDuplex<
|
|
58
|
+
const analyzerstream = new plugins.smartstream.SmartDuplex<
|
|
59
|
+
Buffer,
|
|
60
|
+
IAnalyzedResult
|
|
61
|
+
>({
|
|
55
62
|
readableObjectMode: true,
|
|
56
63
|
writeFunction: async (chunkArg: Buffer, streamtools) => {
|
|
57
64
|
if (firstRun) {
|
|
58
65
|
firstRun = false;
|
|
59
66
|
const fileType = await plugins.fileType.fileTypeFromBuffer(chunkArg);
|
|
60
|
-
const decompressionStream = await this.getDecompressionStream(
|
|
67
|
+
const decompressionStream = await this.getDecompressionStream(
|
|
68
|
+
fileType?.mime as any,
|
|
69
|
+
);
|
|
61
70
|
/**
|
|
62
71
|
* analyzed stream emits once with this object
|
|
63
72
|
*/
|
|
@@ -75,7 +84,7 @@ export class ArchiveAnalyzer {
|
|
|
75
84
|
finalFunction: async (tools) => {
|
|
76
85
|
resultStream.push(null);
|
|
77
86
|
return null;
|
|
78
|
-
}
|
|
87
|
+
},
|
|
79
88
|
});
|
|
80
89
|
return analyzerstream;
|
|
81
90
|
}
|
package/ts/classes.bzip2tools.ts
CHANGED
package/ts/classes.gziptools.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SmartArchive } from './classes.smartarchive.js';
|
|
2
|
-
import * as plugins from './plugins.js'
|
|
2
|
+
import * as plugins from './plugins.js';
|
|
3
3
|
|
|
4
4
|
// This class wraps fflate's gunzip in a Node.js Transform stream
|
|
5
5
|
export class CompressGunzipTransform extends plugins.stream.Transform {
|
|
@@ -7,7 +7,11 @@ export class CompressGunzipTransform extends plugins.stream.Transform {
|
|
|
7
7
|
super();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
_transform(
|
|
10
|
+
_transform(
|
|
11
|
+
chunk: Buffer,
|
|
12
|
+
encoding: BufferEncoding,
|
|
13
|
+
callback: plugins.stream.TransformCallback,
|
|
14
|
+
) {
|
|
11
15
|
plugins.fflate.gunzip(chunk, (err, decompressed) => {
|
|
12
16
|
if (err) {
|
|
13
17
|
callback(err);
|
|
@@ -26,7 +30,11 @@ export class DecompressGunzipTransform extends plugins.stream.Transform {
|
|
|
26
30
|
super();
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
_transform(
|
|
33
|
+
_transform(
|
|
34
|
+
chunk: Buffer,
|
|
35
|
+
encoding: BufferEncoding,
|
|
36
|
+
callback: plugins.stream.TransformCallback,
|
|
37
|
+
) {
|
|
30
38
|
// Use fflate's gunzip function to decompress the chunk
|
|
31
39
|
plugins.fflate.gunzip(chunk, (err, decompressed) => {
|
|
32
40
|
if (err) {
|
|
@@ -41,10 +49,8 @@ export class DecompressGunzipTransform extends plugins.stream.Transform {
|
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
|
|
44
|
-
|
|
45
52
|
export class GzipTools {
|
|
46
|
-
constructor() {
|
|
47
|
-
}
|
|
53
|
+
constructor() {}
|
|
48
54
|
|
|
49
55
|
public getCompressionStream() {
|
|
50
56
|
return new CompressGunzipTransform();
|
|
@@ -6,7 +6,10 @@ import { GzipTools } from './classes.gziptools.js';
|
|
|
6
6
|
import { TarTools } from './classes.tartools.js';
|
|
7
7
|
import { ZipTools } from './classes.ziptools.js';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
ArchiveAnalyzer,
|
|
11
|
+
type IAnalyzedResult,
|
|
12
|
+
} from './classes.archiveanalyzer.js';
|
|
10
13
|
|
|
11
14
|
import type { from } from '@push.rocks/smartrx/dist_ts/smartrx.plugins.rxjs.js';
|
|
12
15
|
|
|
@@ -18,14 +21,19 @@ export class SmartArchive {
|
|
|
18
21
|
return smartArchiveInstance;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
public static async fromArchiveFile(
|
|
24
|
+
public static async fromArchiveFile(
|
|
25
|
+
filePathArg: string,
|
|
26
|
+
): Promise<SmartArchive> {
|
|
22
27
|
const smartArchiveInstance = new SmartArchive();
|
|
23
28
|
smartArchiveInstance.sourceFilePath = filePathArg;
|
|
24
29
|
return smartArchiveInstance;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
public static async fromArchiveStream(
|
|
28
|
-
streamArg:
|
|
33
|
+
streamArg:
|
|
34
|
+
| plugins.stream.Readable
|
|
35
|
+
| plugins.stream.Duplex
|
|
36
|
+
| plugins.stream.Transform,
|
|
29
37
|
): Promise<SmartArchive> {
|
|
30
38
|
const smartArchiveInstance = new SmartArchive();
|
|
31
39
|
smartArchiveInstance.sourceStream = streamArg;
|
|
@@ -41,13 +49,19 @@ export class SmartArchive {
|
|
|
41
49
|
|
|
42
50
|
public sourceUrl: string;
|
|
43
51
|
public sourceFilePath: string;
|
|
44
|
-
public sourceStream:
|
|
52
|
+
public sourceStream:
|
|
53
|
+
| plugins.stream.Readable
|
|
54
|
+
| plugins.stream.Duplex
|
|
55
|
+
| plugins.stream.Transform;
|
|
45
56
|
|
|
46
57
|
public archiveName: string;
|
|
47
58
|
public singleFileMode: boolean = false;
|
|
48
59
|
|
|
49
60
|
public addedDirectories: string[] = [];
|
|
50
|
-
public addedFiles: (
|
|
61
|
+
public addedFiles: (
|
|
62
|
+
| plugins.smartfile.SmartFile
|
|
63
|
+
| plugins.smartfile.StreamFile
|
|
64
|
+
)[] = [];
|
|
51
65
|
public addedUrls: string[] = [];
|
|
52
66
|
|
|
53
67
|
constructor() {}
|
|
@@ -60,7 +74,12 @@ export class SmartArchive {
|
|
|
60
74
|
return this.sourceStream;
|
|
61
75
|
}
|
|
62
76
|
if (this.sourceUrl) {
|
|
63
|
-
const
|
|
77
|
+
const response = await plugins.smartrequest.SmartRequest.create()
|
|
78
|
+
.url(this.sourceUrl)
|
|
79
|
+
.get();
|
|
80
|
+
const webStream = response.stream();
|
|
81
|
+
// @ts-ignore - Web stream to Node.js stream conversion
|
|
82
|
+
const urlStream = plugins.stream.Readable.fromWeb(webStream);
|
|
64
83
|
return urlStream;
|
|
65
84
|
}
|
|
66
85
|
if (this.sourceFilePath) {
|
|
@@ -76,24 +95,35 @@ export class SmartArchive {
|
|
|
76
95
|
// return archiveStream;
|
|
77
96
|
}
|
|
78
97
|
|
|
79
|
-
public async exportToFs(
|
|
98
|
+
public async exportToFs(
|
|
99
|
+
targetDir: string,
|
|
100
|
+
fileNameArg?: string,
|
|
101
|
+
): Promise<void> {
|
|
80
102
|
const done = plugins.smartpromise.defer<void>();
|
|
81
103
|
const streamFileStream = await this.exportToStreamOfStreamFiles();
|
|
82
104
|
streamFileStream.pipe(
|
|
83
105
|
new plugins.smartstream.SmartDuplex({
|
|
84
106
|
objectMode: true,
|
|
85
|
-
writeFunction: async (
|
|
107
|
+
writeFunction: async (
|
|
108
|
+
streamFileArg: plugins.smartfile.StreamFile,
|
|
109
|
+
streamtools,
|
|
110
|
+
) => {
|
|
86
111
|
const done = plugins.smartpromise.defer<void>();
|
|
87
|
-
console.log(
|
|
112
|
+
console.log(
|
|
113
|
+
streamFileArg.relativeFilePath
|
|
114
|
+
? streamFileArg.relativeFilePath
|
|
115
|
+
: 'no relative path',
|
|
116
|
+
);
|
|
88
117
|
const streamFile = streamFileArg;
|
|
89
118
|
const readStream = await streamFile.createReadStream();
|
|
90
119
|
await plugins.smartfile.fs.ensureDir(targetDir);
|
|
91
120
|
const writePath = plugins.path.join(
|
|
92
121
|
targetDir,
|
|
93
|
-
streamFile.relativeFilePath || fileNameArg
|
|
122
|
+
streamFile.relativeFilePath || fileNameArg,
|
|
94
123
|
);
|
|
95
124
|
await plugins.smartfile.fs.ensureDir(plugins.path.dirname(writePath));
|
|
96
|
-
const writeStream =
|
|
125
|
+
const writeStream =
|
|
126
|
+
plugins.smartfile.fsStream.createWriteStream(writePath);
|
|
97
127
|
readStream.pipe(writeStream);
|
|
98
128
|
writeStream.on('finish', () => {
|
|
99
129
|
done.resolve();
|
|
@@ -103,15 +133,16 @@ export class SmartArchive {
|
|
|
103
133
|
finalFunction: async () => {
|
|
104
134
|
done.resolve();
|
|
105
135
|
},
|
|
106
|
-
})
|
|
136
|
+
}),
|
|
107
137
|
);
|
|
108
138
|
return done.promise;
|
|
109
139
|
}
|
|
110
140
|
|
|
111
141
|
public async exportToStreamOfStreamFiles() {
|
|
112
|
-
const streamFileIntake =
|
|
113
|
-
|
|
114
|
-
|
|
142
|
+
const streamFileIntake =
|
|
143
|
+
new plugins.smartstream.StreamIntake<plugins.smartfile.StreamFile>({
|
|
144
|
+
objectMode: true,
|
|
145
|
+
});
|
|
115
146
|
const archiveStream = await this.getArchiveStream();
|
|
116
147
|
const createAnalyzedStream = () => this.archiveAnalyzer.getAnalyzedStream();
|
|
117
148
|
|
|
@@ -120,15 +151,21 @@ export class SmartArchive {
|
|
|
120
151
|
plugins.smartstream.createTransformFunction<IAnalyzedResult, any>(
|
|
121
152
|
async (analyzedResultChunk) => {
|
|
122
153
|
if (analyzedResultChunk.fileType?.mime === 'application/x-tar') {
|
|
123
|
-
const tarStream =
|
|
154
|
+
const tarStream =
|
|
155
|
+
analyzedResultChunk.decompressionStream as plugins.tarStream.Extract;
|
|
124
156
|
tarStream.on('entry', async (header, stream, next) => {
|
|
125
157
|
if (header.type === 'directory') {
|
|
126
|
-
console.log(
|
|
158
|
+
console.log(
|
|
159
|
+
`tar stream directory: ${header.name} ... skipping!`,
|
|
160
|
+
);
|
|
127
161
|
next();
|
|
128
162
|
return;
|
|
129
163
|
}
|
|
130
164
|
console.log(`tar stream file: ${header.name}`);
|
|
131
|
-
const streamfile = plugins.smartfile.StreamFile.fromStream(
|
|
165
|
+
const streamfile = plugins.smartfile.StreamFile.fromStream(
|
|
166
|
+
stream,
|
|
167
|
+
header.name,
|
|
168
|
+
);
|
|
132
169
|
streamFileIntake.push(streamfile);
|
|
133
170
|
stream.on('end', function () {
|
|
134
171
|
next(); // ready for next entry
|
|
@@ -138,20 +175,30 @@ export class SmartArchive {
|
|
|
138
175
|
console.log('finished');
|
|
139
176
|
streamFileIntake.signalEnd();
|
|
140
177
|
});
|
|
141
|
-
analyzedResultChunk.resultStream.pipe(
|
|
178
|
+
analyzedResultChunk.resultStream.pipe(
|
|
179
|
+
analyzedResultChunk.decompressionStream,
|
|
180
|
+
);
|
|
142
181
|
} else if (analyzedResultChunk.fileType?.mime === 'application/zip') {
|
|
143
182
|
analyzedResultChunk.resultStream
|
|
144
183
|
.pipe(analyzedResultChunk.decompressionStream)
|
|
145
|
-
.pipe(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
184
|
+
.pipe(
|
|
185
|
+
new plugins.smartstream.SmartDuplex({
|
|
186
|
+
objectMode: true,
|
|
187
|
+
writeFunction: async (
|
|
188
|
+
streamFileArg: plugins.smartfile.StreamFile,
|
|
189
|
+
streamtools,
|
|
190
|
+
) => {
|
|
191
|
+
streamFileIntake.push(streamFileArg);
|
|
192
|
+
},
|
|
193
|
+
finalFunction: async () => {
|
|
194
|
+
streamFileIntake.signalEnd();
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
} else if (
|
|
199
|
+
analyzedResultChunk.isArchive &&
|
|
200
|
+
analyzedResultChunk.decompressionStream
|
|
201
|
+
) {
|
|
155
202
|
analyzedResultChunk.resultStream
|
|
156
203
|
.pipe(analyzedResultChunk.decompressionStream)
|
|
157
204
|
.pipe(createAnalyzedStream())
|
|
@@ -159,7 +206,7 @@ export class SmartArchive {
|
|
|
159
206
|
} else {
|
|
160
207
|
const streamFile = plugins.smartfile.StreamFile.fromStream(
|
|
161
208
|
analyzedResultChunk.resultStream,
|
|
162
|
-
analyzedResultChunk.fileType?.ext
|
|
209
|
+
analyzedResultChunk.fileType?.ext,
|
|
163
210
|
);
|
|
164
211
|
streamFileIntake.push(streamFile);
|
|
165
212
|
streamFileIntake.signalEnd();
|
|
@@ -167,7 +214,7 @@ export class SmartArchive {
|
|
|
167
214
|
},
|
|
168
215
|
{
|
|
169
216
|
objectMode: true,
|
|
170
|
-
}
|
|
217
|
+
},
|
|
171
218
|
);
|
|
172
219
|
|
|
173
220
|
archiveStream.pipe(createAnalyzedStream()).pipe(createUnpackStream());
|
package/ts/classes.tartools.ts
CHANGED
|
@@ -18,7 +18,7 @@ export class TarTools {
|
|
|
18
18
|
| plugins.smartfile.StreamFile;
|
|
19
19
|
byteLength?: number;
|
|
20
20
|
filePath?: string;
|
|
21
|
-
}
|
|
21
|
+
},
|
|
22
22
|
): Promise<void> {
|
|
23
23
|
return new Promise<void>(async (resolve, reject) => {
|
|
24
24
|
let fileName: string | null = null;
|
|
@@ -28,7 +28,8 @@ export class TarTools {
|
|
|
28
28
|
} else if (optionsArg.content instanceof plugins.smartfile.SmartFile) {
|
|
29
29
|
fileName = (optionsArg.content as plugins.smartfile.SmartFile).relative;
|
|
30
30
|
} else if (optionsArg.content instanceof plugins.smartfile.StreamFile) {
|
|
31
|
-
fileName = (optionsArg.content as plugins.smartfile.StreamFile)
|
|
31
|
+
fileName = (optionsArg.content as plugins.smartfile.StreamFile)
|
|
32
|
+
.relativeFilePath;
|
|
32
33
|
} else if (optionsArg.filePath) {
|
|
33
34
|
fileName = optionsArg.filePath;
|
|
34
35
|
}
|
|
@@ -47,9 +48,11 @@ export class TarTools {
|
|
|
47
48
|
contentByteLength = await optionsArg.content.getSize(); // assuming SmartFile has getSize method
|
|
48
49
|
} else if (optionsArg.content instanceof plugins.smartfile.StreamFile) {
|
|
49
50
|
contentByteLength = await optionsArg.content.getSize(); // assuming StreamFile has getSize method
|
|
50
|
-
} else if (
|
|
51
|
+
} else if (
|
|
52
|
+
optionsArg.content instanceof plugins.smartstream.stream.Readable
|
|
53
|
+
) {
|
|
51
54
|
console.warn(
|
|
52
|
-
'@push.rocks/smartarchive: When streaming, it is recommended to provide byteLength, if known.'
|
|
55
|
+
'@push.rocks/smartarchive: When streaming, it is recommended to provide byteLength, if known.',
|
|
53
56
|
);
|
|
54
57
|
} else if (optionsArg.filePath) {
|
|
55
58
|
const fileStat = await plugins.smartfile.fs.stat(optionsArg.filePath);
|
|
@@ -63,12 +66,18 @@ export class TarTools {
|
|
|
63
66
|
if (Buffer.isBuffer(optionsArg.content)) {
|
|
64
67
|
content = plugins.smartstream.stream.Readable.from(optionsArg.content);
|
|
65
68
|
} else if (typeof optionsArg.content === 'string') {
|
|
66
|
-
content = plugins.smartstream.stream.Readable.from(
|
|
69
|
+
content = plugins.smartstream.stream.Readable.from(
|
|
70
|
+
Buffer.from(optionsArg.content),
|
|
71
|
+
);
|
|
67
72
|
} else if (optionsArg.content instanceof plugins.smartfile.SmartFile) {
|
|
68
|
-
content = plugins.smartstream.stream.Readable.from(
|
|
73
|
+
content = plugins.smartstream.stream.Readable.from(
|
|
74
|
+
optionsArg.content.contents,
|
|
75
|
+
);
|
|
69
76
|
} else if (optionsArg.content instanceof plugins.smartfile.StreamFile) {
|
|
70
77
|
content = await optionsArg.content.createReadStream();
|
|
71
|
-
} else if (
|
|
78
|
+
} else if (
|
|
79
|
+
optionsArg.content instanceof plugins.smartstream.stream.Readable
|
|
80
|
+
) {
|
|
72
81
|
content = optionsArg.content;
|
|
73
82
|
}
|
|
74
83
|
|
|
@@ -87,7 +96,7 @@ export class TarTools {
|
|
|
87
96
|
} else {
|
|
88
97
|
resolve();
|
|
89
98
|
}
|
|
90
|
-
}
|
|
99
|
+
},
|
|
91
100
|
);
|
|
92
101
|
|
|
93
102
|
content.pipe(entry);
|
|
@@ -100,7 +109,10 @@ export class TarTools {
|
|
|
100
109
|
* @param directoryPath
|
|
101
110
|
*/
|
|
102
111
|
public async packDirectory(directoryPath: string) {
|
|
103
|
-
const fileTree = await plugins.smartfile.fs.listFileTree(
|
|
112
|
+
const fileTree = await plugins.smartfile.fs.listFileTree(
|
|
113
|
+
directoryPath,
|
|
114
|
+
'**/*',
|
|
115
|
+
);
|
|
104
116
|
const pack = await this.getPackStream();
|
|
105
117
|
for (const filePath of fileTree) {
|
|
106
118
|
const absolutePath = plugins.path.join(directoryPath, filePath);
|
package/ts/classes.ziptools.ts
CHANGED
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
import type { SmartArchive } from './classes.smartarchive.js';
|
|
2
2
|
import * as plugins from './plugins.js';
|
|
3
3
|
|
|
4
|
-
class DecompressZipTransform extends plugins.smartstream
|
|
4
|
+
class DecompressZipTransform extends plugins.smartstream
|
|
5
|
+
.SmartDuplex<ArrayBufferLike> {
|
|
5
6
|
private streamtools: plugins.smartstream.IStreamTools;
|
|
6
7
|
private unzipper = new plugins.fflate.Unzip(async (fileArg) => {
|
|
7
8
|
let resultBuffer: Buffer;
|
|
8
9
|
fileArg.ondata = async (flateError, dat, final) => {
|
|
9
|
-
resultBuffer
|
|
10
|
-
|
|
10
|
+
resultBuffer
|
|
11
|
+
? (resultBuffer = Buffer.concat([resultBuffer, Buffer.from(dat)]))
|
|
12
|
+
: (resultBuffer = Buffer.from(dat));
|
|
11
13
|
if (final) {
|
|
12
|
-
const streamFile =
|
|
14
|
+
const streamFile =
|
|
15
|
+
plugins.smartfile.StreamFile.fromBuffer(resultBuffer);
|
|
13
16
|
streamFile.relativeFilePath = fileArg.name;
|
|
14
17
|
this.streamtools.push(streamFile);
|
|
15
18
|
}
|
|
16
|
-
}
|
|
19
|
+
};
|
|
17
20
|
fileArg.start();
|
|
18
21
|
});
|
|
19
22
|
constructor() {
|
|
20
23
|
super({
|
|
21
24
|
objectMode: true,
|
|
22
|
-
writeFunction: async (chunkArg
|
|
23
|
-
this.streamtools? null : this.streamtools = streamtoolsArg;
|
|
24
|
-
this.unzipper.push(
|
|
25
|
+
writeFunction: async (chunkArg, streamtoolsArg) => {
|
|
26
|
+
this.streamtools ? null : (this.streamtools = streamtoolsArg);
|
|
27
|
+
this.unzipper.push(
|
|
28
|
+
Buffer.isBuffer(chunkArg) ? chunkArg : Buffer.from(chunkArg),
|
|
29
|
+
false,
|
|
30
|
+
);
|
|
25
31
|
},
|
|
26
32
|
finalFunction: async () => {
|
|
27
33
|
this.unzipper.push(Buffer.from(''), true);
|
|
28
34
|
await plugins.smartdelay.delayFor(0);
|
|
29
35
|
await this.streamtools.push(null);
|
|
30
|
-
}
|
|
36
|
+
},
|
|
31
37
|
});
|
|
32
38
|
this.unzipper.register(plugins.fflate.UnzipInflate);
|
|
33
39
|
}
|
|
@@ -42,7 +48,11 @@ export class CompressZipTransform extends plugins.stream.Transform {
|
|
|
42
48
|
this.files = {};
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
_transform(
|
|
51
|
+
_transform(
|
|
52
|
+
chunk: Buffer,
|
|
53
|
+
encoding: BufferEncoding,
|
|
54
|
+
callback: plugins.stream.TransformCallback,
|
|
55
|
+
) {
|
|
46
56
|
// Simple example: storing chunks in memory before finalizing ZIP in _flush
|
|
47
57
|
this.files['file.txt'] = new Uint8Array(chunk);
|
|
48
58
|
callback();
|
|
@@ -61,8 +71,7 @@ export class CompressZipTransform extends plugins.stream.Transform {
|
|
|
61
71
|
}
|
|
62
72
|
|
|
63
73
|
export class ZipTools {
|
|
64
|
-
constructor() {
|
|
65
|
-
}
|
|
74
|
+
constructor() {}
|
|
66
75
|
|
|
67
76
|
public getCompressionStream() {
|
|
68
77
|
return new CompressZipTransform();
|
package/ts/paths.ts
CHANGED
package/ts/plugins.ts
CHANGED
|
@@ -15,7 +15,17 @@ import * as smartstream from '@push.rocks/smartstream';
|
|
|
15
15
|
import * as smartrx from '@push.rocks/smartrx';
|
|
16
16
|
import * as smarturl from '@push.rocks/smarturl';
|
|
17
17
|
|
|
18
|
-
export {
|
|
18
|
+
export {
|
|
19
|
+
smartfile,
|
|
20
|
+
smartdelay,
|
|
21
|
+
smartpath,
|
|
22
|
+
smartpromise,
|
|
23
|
+
smartrequest,
|
|
24
|
+
smartunique,
|
|
25
|
+
smartstream,
|
|
26
|
+
smartrx,
|
|
27
|
+
smarturl,
|
|
28
|
+
};
|
|
19
29
|
|
|
20
30
|
// third party scope
|
|
21
31
|
import * as fileType from 'file-type';
|