@push.rocks/smartarchive 3.0.7 → 4.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/classes.archiveanalyzer.d.ts +17 -0
- package/dist_ts/classes.archiveanalyzer.js +57 -0
- package/dist_ts/classes.bzip2tools.d.ts +15 -0
- package/dist_ts/classes.bzip2tools.js +36 -0
- package/dist_ts/classes.gziptools.d.ts +18 -0
- package/dist_ts/classes.gziptools.js +51 -0
- package/dist_ts/classes.smartarchive.d.ts +31 -0
- package/dist_ts/classes.smartarchive.js +91 -0
- package/dist_ts/classes.tartools.d.ts +10 -0
- package/dist_ts/classes.tartools.js +30 -0
- package/dist_ts/index.d.ts +1 -1
- package/dist_ts/index.js +2 -2
- package/dist_ts/paths.d.ts +2 -0
- package/dist_ts/paths.js +4 -0
- package/dist_ts/plugins.d.ts +17 -0
- package/dist_ts/plugins.js +21 -0
- package/package.json +17 -15
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.archiveanalyzer.ts +74 -0
- package/ts/classes.bzip2tools.ts +45 -0
- package/ts/classes.gziptools.ts +59 -0
- package/ts/classes.smartarchive.ts +120 -0
- package/ts/classes.tartools.ts +36 -0
- package/ts/index.ts +1 -1
- package/ts/{smartarchive.paths.ts → paths.ts} +1 -1
- package/ts/{smartarchive.plugins.ts → plugins.ts} +8 -7
- package/ts/smartarchive.classes.smartarchive.ts +0 -133
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartarchive',
|
|
6
|
-
version: '
|
|
6
|
+
version: '4.0.0',
|
|
7
7
|
description: 'work with archives'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSwwQkFBMEI7SUFDaEMsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLG9CQUFvQjtDQUNsQyxDQUFBIn0=
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { SmartArchive } from './classes.smartarchive.js';
|
|
4
|
+
import * as plugins from './plugins.js';
|
|
5
|
+
export interface IAnalyzedResult {
|
|
6
|
+
fileType: plugins.fileType.FileTypeResult;
|
|
7
|
+
isArchive: boolean;
|
|
8
|
+
resultStream: plugins.smartstream.PassThrough;
|
|
9
|
+
decompressionStream: plugins.stream.Transform | plugins.stream.Duplex | plugins.tarStream.Extract;
|
|
10
|
+
}
|
|
11
|
+
export declare class ArchiveAnalyzer {
|
|
12
|
+
smartArchiveRef: SmartArchive;
|
|
13
|
+
constructor(smartArchiveRefArg: SmartArchive);
|
|
14
|
+
private mimeTypeIsArchive;
|
|
15
|
+
private getDecompressionStream;
|
|
16
|
+
getAnalyzedStream(): plugins.smartstream.SmartDuplex<Buffer, IAnalyzedResult>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
export class ArchiveAnalyzer {
|
|
3
|
+
constructor(smartArchiveRefArg) {
|
|
4
|
+
this.smartArchiveRef = smartArchiveRefArg;
|
|
5
|
+
}
|
|
6
|
+
async mimeTypeIsArchive(mimeType) {
|
|
7
|
+
const archiveMimeTypes = new Set([
|
|
8
|
+
'application/zip',
|
|
9
|
+
'application/x-rar-compressed',
|
|
10
|
+
'application/x-tar',
|
|
11
|
+
'application/gzip',
|
|
12
|
+
'application/x-7z-compressed',
|
|
13
|
+
'application/x-bzip2',
|
|
14
|
+
// Add other archive mime types here
|
|
15
|
+
]);
|
|
16
|
+
return archiveMimeTypes.has(mimeType);
|
|
17
|
+
}
|
|
18
|
+
getDecompressionStream(mimeTypeArg) {
|
|
19
|
+
switch (mimeTypeArg) {
|
|
20
|
+
case 'application/gzip':
|
|
21
|
+
return this.smartArchiveRef.gzipTools.getDecompressionStream();
|
|
22
|
+
case 'application/x-bzip2':
|
|
23
|
+
return this.smartArchiveRef.bzip2Tools.getDecompressionStream(); // replace with your own bzip2 decompression stream
|
|
24
|
+
case 'application/x-tar':
|
|
25
|
+
return this.smartArchiveRef.tarTools.getDecompressionStream(); // replace with your own tar decompression stream
|
|
26
|
+
default:
|
|
27
|
+
// Handle unsupported formats or no decompression needed
|
|
28
|
+
return new plugins.smartstream.PassThrough();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getAnalyzedStream() {
|
|
32
|
+
let firstRun = true;
|
|
33
|
+
const resultStream = new plugins.smartstream.PassThrough();
|
|
34
|
+
const analyzerstream = new plugins.smartstream.SmartDuplex({
|
|
35
|
+
readableObjectMode: true,
|
|
36
|
+
writeAndTransformFunction: async (chunkArg, streamtools) => {
|
|
37
|
+
const fileType = await plugins.fileType.fileTypeFromBuffer(chunkArg);
|
|
38
|
+
const decompressionStream = this.getDecompressionStream(fileType.mime);
|
|
39
|
+
resultStream.push(chunkArg);
|
|
40
|
+
if (firstRun) {
|
|
41
|
+
firstRun = false;
|
|
42
|
+
const result = {
|
|
43
|
+
fileType,
|
|
44
|
+
isArchive: await this.mimeTypeIsArchive(fileType.mime),
|
|
45
|
+
resultStream,
|
|
46
|
+
decompressionStream,
|
|
47
|
+
};
|
|
48
|
+
streamtools.push(result);
|
|
49
|
+
streamtools.push(null);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
return analyzerstream;
|
|
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0FBQyxDQUFDO29CQUN6QixXQUFXLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFDO29CQUN2QixPQUFPLElBQUksQ0FBQztpQkFDYjtZQUNILENBQUM7U0FDRixDQUFDLENBQUM7UUFDSCxPQUFPLGNBQWMsQ0FBQztJQUN4QixDQUFDO0NBQ0YifQ==
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { SmartArchive } from './classes.smartarchive.js';
|
|
4
|
+
import * as plugins from './plugins.js';
|
|
5
|
+
export declare class DecompressBzip2Transform extends plugins.stream.Transform {
|
|
6
|
+
private bzip2Decompressor;
|
|
7
|
+
constructor();
|
|
8
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback): void;
|
|
9
|
+
_flush(callback: plugins.stream.TransformCallback): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class Bzip2Tools {
|
|
12
|
+
smartArchiveRef: SmartArchive;
|
|
13
|
+
constructor(smartArchiveRefArg: SmartArchive);
|
|
14
|
+
getDecompressionStream(): DecompressBzip2Transform;
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
export class DecompressBzip2Transform extends plugins.stream.Transform {
|
|
3
|
+
constructor() {
|
|
4
|
+
super();
|
|
5
|
+
// Initialize the bzip2 decompressor once here
|
|
6
|
+
this.bzip2Decompressor = plugins.unbzip2Stream();
|
|
7
|
+
this.bzip2Decompressor.on('data', (data) => {
|
|
8
|
+
// When data is decompressed, push it to the stream
|
|
9
|
+
this.push(data);
|
|
10
|
+
});
|
|
11
|
+
this.bzip2Decompressor.on('error', (err) => {
|
|
12
|
+
// If an error occurs, emit it on this stream
|
|
13
|
+
this.emit('error', err);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_transform(chunk, encoding, callback) {
|
|
17
|
+
// Pass the chunk directly to the decompressor
|
|
18
|
+
// The decompressor will handle the state across chunks
|
|
19
|
+
this.bzip2Decompressor.write(chunk);
|
|
20
|
+
callback();
|
|
21
|
+
}
|
|
22
|
+
_flush(callback) {
|
|
23
|
+
// When the stream is ending, end the decompressor stream as well
|
|
24
|
+
this.bzip2Decompressor.end();
|
|
25
|
+
callback();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class Bzip2Tools {
|
|
29
|
+
constructor(smartArchiveRefArg) {
|
|
30
|
+
this.smartArchiveRef = smartArchiveRefArg;
|
|
31
|
+
}
|
|
32
|
+
getDecompressionStream() {
|
|
33
|
+
return new DecompressBzip2Transform();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5iemlwMnRvb2xzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvY2xhc3Nlcy5iemlwMnRvb2xzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxPQUFPLE1BQU0sY0FBYyxDQUFDO0FBRXhDLE1BQU0sT0FBTyx3QkFBeUIsU0FBUSxPQUFPLENBQUMsTUFBTSxDQUFDLFNBQVM7SUFHcEU7UUFDRSxLQUFLLEVBQUUsQ0FBQztRQUNSLDhDQUE4QztRQUM5QyxJQUFJLENBQUMsaUJBQWlCLEdBQUcsT0FBTyxDQUFDLGFBQWEsRUFBRSxDQUFDO1FBQ2pELElBQUksQ0FBQyxpQkFBaUIsQ0FBQyxFQUFFLENBQUMsTUFBTSxFQUFFLENBQUMsSUFBWSxFQUFFLEVBQUU7WUFDakQsbURBQW1EO1lBQ25ELElBQUksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDbEIsQ0FBQyxDQUFDLENBQUM7UUFDSCxJQUFJLENBQUMsaUJBQWlCLENBQUMsRUFBRSxDQUFDLE9BQU8sRUFBRSxDQUFDLEdBQUcsRUFBRSxFQUFFO1lBQ3pDLDZDQUE2QztZQUM3QyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxHQUFHLENBQUMsQ0FBQztRQUMxQixDQUFDLENBQUMsQ0FBQztJQUNMLENBQUM7SUFFRCxVQUFVLENBQUMsS0FBYSxFQUFFLFFBQXdCLEVBQUUsUUFBMEM7UUFDNUYsOENBQThDO1FBQzlDLHVEQUF1RDtRQUN2RCxJQUFJLENBQUMsaUJBQWlCLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxDQUFDO1FBQ3BDLFFBQVEsRUFBRSxDQUFDO0lBQ2IsQ0FBQztJQUVELE1BQU0sQ0FBQyxRQUEwQztRQUMvQyxpRUFBaUU7UUFDakUsSUFBSSxDQUFDLGlCQUFpQixDQUFDLEdBQUcsRUFBRSxDQUFDO1FBQzdCLFFBQVEsRUFBRSxDQUFDO0lBQ2IsQ0FBQztDQUNGO0FBRUQsTUFBTSxPQUFPLFVBQVU7SUFHckIsWUFBWSxrQkFBZ0M7UUFDMUMsSUFBSSxDQUFDLGVBQWUsR0FBRyxrQkFBa0IsQ0FBQztJQUM1QyxDQUFDO0lBRUQsc0JBQXNCO1FBQ3BCLE9BQU8sSUFBSSx3QkFBd0IsRUFBRSxDQUFDO0lBQ3hDLENBQUM7Q0FDRiJ9
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type { SmartArchive } from './classes.smartarchive.js';
|
|
4
|
+
import * as plugins from './plugins.js';
|
|
5
|
+
export declare class CompressGunzipTransform extends plugins.stream.Transform {
|
|
6
|
+
constructor();
|
|
7
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback): void;
|
|
8
|
+
}
|
|
9
|
+
export declare class DecompressGunzipTransform extends plugins.stream.Transform {
|
|
10
|
+
constructor();
|
|
11
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback): void;
|
|
12
|
+
}
|
|
13
|
+
export declare class GzipTools {
|
|
14
|
+
smartArchiveRef: SmartArchive;
|
|
15
|
+
constructor(smartArchiveRefArg: SmartArchive);
|
|
16
|
+
getCompressionStream(): CompressGunzipTransform;
|
|
17
|
+
getDecompressionStream(): DecompressGunzipTransform;
|
|
18
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
// This class wraps fflate's gunzip in a Node.js Transform stream
|
|
3
|
+
export class CompressGunzipTransform extends plugins.stream.Transform {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
}
|
|
7
|
+
_transform(chunk, encoding, callback) {
|
|
8
|
+
plugins.fflate.gunzip(chunk, (err, decompressed) => {
|
|
9
|
+
if (err) {
|
|
10
|
+
callback(err);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.push(decompressed);
|
|
14
|
+
callback();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// DecompressGunzipTransform class that extends the Node.js Transform stream to
|
|
20
|
+
// create a stream that decompresses GZip-compressed data using fflate's gunzip function
|
|
21
|
+
export class DecompressGunzipTransform extends plugins.stream.Transform {
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
}
|
|
25
|
+
_transform(chunk, encoding, callback) {
|
|
26
|
+
// Use fflate's gunzip function to decompress the chunk
|
|
27
|
+
plugins.fflate.gunzip(chunk, (err, decompressed) => {
|
|
28
|
+
if (err) {
|
|
29
|
+
// If an error occurs during decompression, pass the error to the callback
|
|
30
|
+
callback(err);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// If decompression is successful, push the decompressed data into the stream
|
|
34
|
+
this.push(decompressed);
|
|
35
|
+
callback();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class GzipTools {
|
|
41
|
+
constructor(smartArchiveRefArg) {
|
|
42
|
+
this.smartArchiveRef = smartArchiveRefArg;
|
|
43
|
+
}
|
|
44
|
+
getCompressionStream() {
|
|
45
|
+
return new CompressGunzipTransform();
|
|
46
|
+
}
|
|
47
|
+
getDecompressionStream() {
|
|
48
|
+
return new DecompressGunzipTransform();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5nemlwdG9vbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jbGFzc2VzLmd6aXB0b29scy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssT0FBTyxNQUFNLGNBQWMsQ0FBQTtBQUV2QyxpRUFBaUU7QUFDakUsTUFBTSxPQUFPLHVCQUF3QixTQUFRLE9BQU8sQ0FBQyxNQUFNLENBQUMsU0FBUztJQUNuRTtRQUNFLEtBQUssRUFBRSxDQUFDO0lBQ1YsQ0FBQztJQUVELFVBQVUsQ0FBQyxLQUFhLEVBQUUsUUFBd0IsRUFBRSxRQUEwQztRQUM1RixPQUFPLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxLQUFLLEVBQUUsQ0FBQyxHQUFHLEVBQUUsWUFBWSxFQUFFLEVBQUU7WUFDakQsSUFBSSxHQUFHLEVBQUU7Z0JBQ1AsUUFBUSxDQUFDLEdBQUcsQ0FBQyxDQUFDO2FBQ2Y7aUJBQU07Z0JBQ0wsSUFBSSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQztnQkFDeEIsUUFBUSxFQUFFLENBQUM7YUFDWjtRQUNILENBQUMsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztDQUNGO0FBRUQsK0VBQStFO0FBQy9FLHdGQUF3RjtBQUN4RixNQUFNLE9BQU8seUJBQTBCLFNBQVEsT0FBTyxDQUFDLE1BQU0sQ0FBQyxTQUFTO0lBQ3JFO1FBQ0UsS0FBSyxFQUFFLENBQUM7SUFDVixDQUFDO0lBRUQsVUFBVSxDQUFDLEtBQWEsRUFBRSxRQUF3QixFQUFFLFFBQTBDO1FBQzVGLHVEQUF1RDtRQUN2RCxPQUFPLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxLQUFLLEVBQUUsQ0FBQyxHQUFHLEVBQUUsWUFBWSxFQUFFLEVBQUU7WUFDakQsSUFBSSxHQUFHLEVBQUU7Z0JBQ1AsMEVBQTBFO2dCQUMxRSxRQUFRLENBQUMsR0FBRyxDQUFDLENBQUM7YUFDZjtpQkFBTTtnQkFDTCw2RUFBNkU7Z0JBQzdFLElBQUksQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLENBQUM7Z0JBQ3hCLFFBQVEsRUFBRSxDQUFDO2FBQ1o7UUFDSCxDQUFDLENBQUMsQ0FBQztJQUNMLENBQUM7Q0FDRjtBQUdELE1BQU0sT0FBTyxTQUFTO0lBR3BCLFlBQVksa0JBQWdDO1FBQzFDLElBQUksQ0FBQyxlQUFlLEdBQUcsa0JBQWtCLENBQUM7SUFDNUMsQ0FBQztJQUVNLG9CQUFvQjtRQUN6QixPQUFPLElBQUksdUJBQXVCLEVBQUUsQ0FBQztJQUN2QyxDQUFDO0lBRU0sc0JBQXNCO1FBQzNCLE9BQU8sSUFBSSx5QkFBeUIsRUFBRSxDQUFDO0lBQ3pDLENBQUM7Q0FDRiJ9
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import * as plugins from './plugins.js';
|
|
3
|
+
import { GzipTools } from './classes.gziptools.js';
|
|
4
|
+
import { TarTools } from './classes.tartools.js';
|
|
5
|
+
import { Bzip2Tools } from './classes.bzip2tools.js';
|
|
6
|
+
import { ArchiveAnalyzer } from './classes.archiveanalyzer.js';
|
|
7
|
+
export declare class SmartArchive {
|
|
8
|
+
static fromArchiveUrl(urlArg: string): Promise<SmartArchive>;
|
|
9
|
+
static fromArchiveFile(filePathArg: string): Promise<SmartArchive>;
|
|
10
|
+
static fromArchiveStream(streamArg: plugins.stream.Readable | plugins.stream.Duplex | plugins.stream.Transform): Promise<SmartArchive>;
|
|
11
|
+
tarTools: TarTools;
|
|
12
|
+
gzipTools: GzipTools;
|
|
13
|
+
bzip2Tools: Bzip2Tools;
|
|
14
|
+
archiveAnalyzer: ArchiveAnalyzer;
|
|
15
|
+
sourceUrl: string;
|
|
16
|
+
sourceFilePath: string;
|
|
17
|
+
sourceStream: plugins.stream.Readable | plugins.stream.Duplex | plugins.stream.Transform;
|
|
18
|
+
archiveName: string;
|
|
19
|
+
singleFileMode: boolean;
|
|
20
|
+
addedDirectories: string[];
|
|
21
|
+
addedFiles: (plugins.smartfile.SmartFile | plugins.smartfile.StreamFile)[];
|
|
22
|
+
addedUrls: string[];
|
|
23
|
+
constructor();
|
|
24
|
+
/**
|
|
25
|
+
* gets the original archive stream
|
|
26
|
+
*/
|
|
27
|
+
getArchiveStream(): Promise<plugins.stream.Readable | plugins.stream.Duplex>;
|
|
28
|
+
exportToTarGzStream(): Promise<void>;
|
|
29
|
+
exportToFs(targetDir: string): Promise<void>;
|
|
30
|
+
exportToStreamOfStreamFiles(): Promise<plugins.smartstream.StreamIntake<plugins.smartfile.StreamFile>>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import * as paths from './paths.js';
|
|
3
|
+
import { GzipTools } from './classes.gziptools.js';
|
|
4
|
+
import { TarTools } from './classes.tartools.js';
|
|
5
|
+
import { Bzip2Tools } from './classes.bzip2tools.js';
|
|
6
|
+
import { ArchiveAnalyzer } from './classes.archiveanalyzer.js';
|
|
7
|
+
export class SmartArchive {
|
|
8
|
+
// STATIC
|
|
9
|
+
static async fromArchiveUrl(urlArg) {
|
|
10
|
+
const smartArchiveInstance = new SmartArchive();
|
|
11
|
+
smartArchiveInstance.sourceUrl = urlArg;
|
|
12
|
+
return smartArchiveInstance;
|
|
13
|
+
}
|
|
14
|
+
static async fromArchiveFile(filePathArg) {
|
|
15
|
+
const smartArchiveInstance = new SmartArchive();
|
|
16
|
+
smartArchiveInstance.sourceFilePath = filePathArg;
|
|
17
|
+
return smartArchiveInstance;
|
|
18
|
+
}
|
|
19
|
+
static async fromArchiveStream(streamArg) {
|
|
20
|
+
const smartArchiveInstance = new SmartArchive();
|
|
21
|
+
smartArchiveInstance.sourceStream = streamArg;
|
|
22
|
+
return smartArchiveInstance;
|
|
23
|
+
}
|
|
24
|
+
constructor() {
|
|
25
|
+
// INSTANCE
|
|
26
|
+
this.tarTools = new TarTools(this);
|
|
27
|
+
this.gzipTools = new GzipTools(this);
|
|
28
|
+
this.bzip2Tools = new Bzip2Tools(this);
|
|
29
|
+
this.archiveAnalyzer = new ArchiveAnalyzer(this);
|
|
30
|
+
this.singleFileMode = false;
|
|
31
|
+
this.addedDirectories = [];
|
|
32
|
+
this.addedFiles = [];
|
|
33
|
+
this.addedUrls = [];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* gets the original archive stream
|
|
37
|
+
*/
|
|
38
|
+
async getArchiveStream() {
|
|
39
|
+
if (this.sourceStream) {
|
|
40
|
+
return this.sourceStream;
|
|
41
|
+
}
|
|
42
|
+
if (this.sourceUrl) {
|
|
43
|
+
const urlStream = await plugins.smartrequest.getStream(this.sourceUrl);
|
|
44
|
+
return urlStream;
|
|
45
|
+
}
|
|
46
|
+
if (this.sourceFilePath) {
|
|
47
|
+
const fileStream = plugins.smartfile.fs.toReadStream(this.sourceFilePath);
|
|
48
|
+
return fileStream;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async exportToTarGzStream() {
|
|
52
|
+
const tarPackStream = await this.tarTools.getPackStream();
|
|
53
|
+
const gzipStream = await this.gzipTools.getCompressionStream();
|
|
54
|
+
// const archiveStream = tarPackStream.pipe(gzipStream);
|
|
55
|
+
// return archiveStream;
|
|
56
|
+
}
|
|
57
|
+
async exportToFs(targetDir) { }
|
|
58
|
+
async exportToStreamOfStreamFiles() {
|
|
59
|
+
const streamFileIntake = new plugins.smartstream.StreamIntake({
|
|
60
|
+
objectMode: true,
|
|
61
|
+
});
|
|
62
|
+
const archiveStream = await this.getArchiveStream();
|
|
63
|
+
const createAnalyzedStream = () => this.archiveAnalyzer.getAnalyzedStream();
|
|
64
|
+
// lets create a function that can be called multiple times to unpack layers of archives
|
|
65
|
+
const createUnpackStream = () => plugins.smartstream.createTransformFunction(async (analyzedResultChunk) => {
|
|
66
|
+
if (analyzedResultChunk.fileType.mime === 'application/x-tar') {
|
|
67
|
+
analyzedResultChunk.decompressionStream.on('entry', async (header, stream, next) => {
|
|
68
|
+
const streamfile = plugins.smartfile.StreamFile.fromStream(stream, header.name);
|
|
69
|
+
streamFileIntake.push(streamfile);
|
|
70
|
+
stream.on('end', function () {
|
|
71
|
+
next(); // ready for next entry
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
analyzedResultChunk.resultStream.pipe(analyzedResultChunk.decompressionStream);
|
|
75
|
+
}
|
|
76
|
+
else if (analyzedResultChunk.isArchive && analyzedResultChunk.decompressionStream) {
|
|
77
|
+
analyzedResultChunk.resultStream
|
|
78
|
+
.pipe(analyzedResultChunk.decompressionStream)
|
|
79
|
+
.pipe(createAnalyzedStream())
|
|
80
|
+
.pipe(createUnpackStream());
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const streamFile = plugins.smartfile.StreamFile.fromStream(analyzedResultChunk.resultStream, analyzedResultChunk.fileType.ext);
|
|
84
|
+
streamFileIntake.push(streamFile);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
archiveStream.pipe(createAnalyzedStream()).pipe(createUnpackStream());
|
|
88
|
+
return streamFileIntake;
|
|
89
|
+
}
|
|
90
|
+
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FBSSxDQUFDLGtCQUFrQixFQUFFLENBQUMsQ0FBQztRQUN0RSxPQUFPLGdCQUFnQixDQUFDO0lBQzFCLENBQUM7Q0FDRiJ9
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { SmartArchive } from './classes.smartarchive.js';
|
|
3
|
+
import * as plugins from './plugins.js';
|
|
4
|
+
export declare class TarTools {
|
|
5
|
+
smartArchiveRef: SmartArchive;
|
|
6
|
+
constructor(smartArchiveRefArg: SmartArchive);
|
|
7
|
+
addFileToPack(pack: plugins.tarStream.Pack, fileName: string, content: string | Buffer): Promise<void>;
|
|
8
|
+
getPackStream(): Promise<plugins.tarStream.Pack>;
|
|
9
|
+
getDecompressionStream(): plugins.tarStream.Extract;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
export class TarTools {
|
|
3
|
+
constructor(smartArchiveRefArg) {
|
|
4
|
+
this.smartArchiveRef = smartArchiveRefArg;
|
|
5
|
+
}
|
|
6
|
+
// packing
|
|
7
|
+
addFileToPack(pack, fileName, content) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const entry = pack.entry({ name: fileName, size: content.length }, (err) => {
|
|
10
|
+
if (err) {
|
|
11
|
+
reject(err);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
resolve();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
entry.write(content);
|
|
18
|
+
entry.end();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async getPackStream() {
|
|
22
|
+
const pack = plugins.tarStream.pack();
|
|
23
|
+
return pack;
|
|
24
|
+
}
|
|
25
|
+
// extracting
|
|
26
|
+
getDecompressionStream() {
|
|
27
|
+
return plugins.tarStream.extract();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uI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QUVELGFBQWE7SUFDYixzQkFBc0I7UUFDcEIsT0FBTyxPQUFPLENBQUMsU0FBUyxDQUFDLE9BQU8sRUFBRSxDQUFDO0lBQ3JDLENBQUM7Q0FDRiJ9
|
package/dist_ts/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './classes.smartarchive.js';
|
package/dist_ts/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
1
|
+
export * from './classes.smartarchive.js';
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLDJCQUEyQixDQUFDIn0=
|
package/dist_ts/paths.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
|
|
3
|
+
export const nogitDir = plugins.path.join(packageDir, './.nogit');
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGF0aHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9wYXRocy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLGNBQWMsQ0FBQztBQUV4QyxNQUFNLENBQUMsTUFBTSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQ3pDLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQy9ELEtBQUssQ0FDTixDQUFDO0FBQ0YsTUFBTSxDQUFDLE1BQU0sUUFBUSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxVQUFVLENBQUMsQ0FBQyJ9
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as stream from 'stream';
|
|
3
|
+
export { path, stream };
|
|
4
|
+
import * as smartfile from '@push.rocks/smartfile';
|
|
5
|
+
import * as smartpath from '@push.rocks/smartpath';
|
|
6
|
+
import * as smartpromise from '@push.rocks/smartpromise';
|
|
7
|
+
import * as smartrequest from '@push.rocks/smartrequest';
|
|
8
|
+
import * as smartunique from '@push.rocks/smartunique';
|
|
9
|
+
import * as smartstream from '@push.rocks/smartstream';
|
|
10
|
+
import * as smartrx from '@push.rocks/smartrx';
|
|
11
|
+
import * as smarturl from '@push.rocks/smarturl';
|
|
12
|
+
export { smartfile, smartpath, smartpromise, smartrequest, smartunique, smartstream, smartrx, smarturl };
|
|
13
|
+
import * as fileType from 'file-type';
|
|
14
|
+
import * as fflate from 'fflate';
|
|
15
|
+
import tarStream from 'tar-stream';
|
|
16
|
+
import unbzip2Stream from 'unbzip2-stream';
|
|
17
|
+
export { fileType, fflate, tarStream, unbzip2Stream };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// node native scope
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as stream from 'stream';
|
|
4
|
+
export { path, stream };
|
|
5
|
+
// @pushrocks scope
|
|
6
|
+
import * as smartfile from '@push.rocks/smartfile';
|
|
7
|
+
import * as smartpath from '@push.rocks/smartpath';
|
|
8
|
+
import * as smartpromise from '@push.rocks/smartpromise';
|
|
9
|
+
import * as smartrequest from '@push.rocks/smartrequest';
|
|
10
|
+
import * as smartunique from '@push.rocks/smartunique';
|
|
11
|
+
import * as smartstream from '@push.rocks/smartstream';
|
|
12
|
+
import * as smartrx from '@push.rocks/smartrx';
|
|
13
|
+
import * as smarturl from '@push.rocks/smarturl';
|
|
14
|
+
export { smartfile, smartpath, smartpromise, smartrequest, smartunique, smartstream, smartrx, smarturl };
|
|
15
|
+
// third party scope
|
|
16
|
+
import * as fileType from 'file-type';
|
|
17
|
+
import * as fflate from 'fflate';
|
|
18
|
+
import tarStream from 'tar-stream';
|
|
19
|
+
import unbzip2Stream from 'unbzip2-stream';
|
|
20
|
+
export { fileType, fflate, tarStream, unbzip2Stream };
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3BsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsb0JBQW9CO0FBQ3BCLE9BQU8sS0FBSyxJQUFJLE1BQU0sTUFBTSxDQUFDO0FBQzdCLE9BQU8sS0FBSyxNQUFNLE1BQU0sUUFBUSxDQUFDO0FBRWpDLE9BQU8sRUFBRSxJQUFJLEVBQUUsTUFBTSxFQUFFLENBQUM7QUFFeEIsbUJBQW1CO0FBQ25CLE9BQU8sS0FBSyxTQUFTLE1BQU0sdUJBQXVCLENBQUM7QUFDbkQsT0FBTyxLQUFLLFNBQVMsTUFBTSx1QkFBdUIsQ0FBQztBQUNuRCxPQUFPLEtBQUssWUFBWSxNQUFNLDBCQUEwQixDQUFDO0FBQ3pELE9BQU8sS0FBSyxZQUFZLE1BQU0sMEJBQTBCLENBQUM7QUFDekQsT0FBTyxLQUFLLFdBQVcsTUFBTSx5QkFBeUIsQ0FBQztBQUN2RCxPQUFPLEtBQUssV0FBVyxNQUFNLHlCQUF5QixDQUFDO0FBQ3ZELE9BQU8sS0FBSyxPQUFPLE1BQU0scUJBQXFCLENBQUM7QUFDL0MsT0FBTyxLQUFLLFFBQVEsTUFBTSxzQkFBc0IsQ0FBQztBQUVqRCxPQUFPLEVBQUUsU0FBUyxFQUFFLFNBQVMsRUFBRSxZQUFZLEVBQUUsWUFBWSxFQUFFLFdBQVcsRUFBRSxXQUFXLEVBQUUsT0FBTyxFQUFFLFFBQVEsRUFBRSxDQUFDO0FBRXpHLG9CQUFvQjtBQUNwQixPQUFPLEtBQUssUUFBUSxNQUFNLFdBQVcsQ0FBQztBQUN0QyxPQUFPLEtBQUssTUFBTSxNQUFNLFFBQVEsQ0FBQztBQUNqQyxPQUFPLFNBQVMsTUFBTSxZQUFZLENBQUM7QUFDbkMsT0FBTyxhQUFhLE1BQU0sZ0JBQWdCLENBQUM7QUFFM0MsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLEVBQUUsU0FBUyxFQUFFLGFBQWEsRUFBRSxDQUFDIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartarchive",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "work with archives",
|
|
5
5
|
"main": "dist_ts/index.js",
|
|
6
6
|
"typings": "dist_ts/index.d.ts",
|
|
@@ -21,24 +21,26 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/pushrocks/smartarchive#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@push.rocks/smartfile": "^
|
|
24
|
+
"@push.rocks/smartfile": "^11.0.0",
|
|
25
25
|
"@push.rocks/smartpath": "^5.0.11",
|
|
26
26
|
"@push.rocks/smartpromise": "^4.0.3",
|
|
27
|
-
"@push.rocks/smartrequest": "^2.0.
|
|
28
|
-
"@push.rocks/smartrx": "^3.0.
|
|
29
|
-
"@push.rocks/smartstream": "^
|
|
30
|
-
"@push.rocks/smartunique": "^3.0.
|
|
31
|
-
"@
|
|
32
|
-
"@types/tar-stream": "^
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
27
|
+
"@push.rocks/smartrequest": "^2.0.20",
|
|
28
|
+
"@push.rocks/smartrx": "^3.0.7",
|
|
29
|
+
"@push.rocks/smartstream": "^3.0.7",
|
|
30
|
+
"@push.rocks/smartunique": "^3.0.6",
|
|
31
|
+
"@push.rocks/smarturl": "^3.0.7",
|
|
32
|
+
"@types/tar-stream": "^3.1.2",
|
|
33
|
+
"@types/unbzip2-stream": "^1.4.2",
|
|
34
|
+
"fflate": "^0.8.1",
|
|
35
|
+
"file-type": "^18.6.0",
|
|
36
|
+
"tar-stream": "^3.1.6",
|
|
37
|
+
"unbzip2-stream": "^1.4.3"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@push.rocks/tapbundle": "^5.0.
|
|
40
|
+
"@git.zone/tsbuild": "^2.1.66",
|
|
41
|
+
"@git.zone/tsrun": "^1.2.44",
|
|
42
|
+
"@git.zone/tstest": "^1.0.77",
|
|
43
|
+
"@push.rocks/tapbundle": "^5.0.15"
|
|
42
44
|
},
|
|
43
45
|
"private": false,
|
|
44
46
|
"files": [
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { SmartArchive } from './classes.smartarchive.js';
|
|
2
|
+
import * as plugins from './plugins.js';
|
|
3
|
+
|
|
4
|
+
export interface IAnalyzedResult {
|
|
5
|
+
fileType: plugins.fileType.FileTypeResult;
|
|
6
|
+
isArchive: boolean;
|
|
7
|
+
resultStream: plugins.smartstream.PassThrough;
|
|
8
|
+
decompressionStream: plugins.stream.Transform | plugins.stream.Duplex | plugins.tarStream.Extract;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ArchiveAnalyzer {
|
|
12
|
+
smartArchiveRef: SmartArchive;
|
|
13
|
+
|
|
14
|
+
constructor(smartArchiveRefArg: SmartArchive) {
|
|
15
|
+
this.smartArchiveRef = smartArchiveRefArg;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private async mimeTypeIsArchive(mimeType: string): Promise<boolean> {
|
|
19
|
+
const archiveMimeTypes: Set<string> = new Set([
|
|
20
|
+
'application/zip',
|
|
21
|
+
'application/x-rar-compressed',
|
|
22
|
+
'application/x-tar',
|
|
23
|
+
'application/gzip',
|
|
24
|
+
'application/x-7z-compressed',
|
|
25
|
+
'application/x-bzip2',
|
|
26
|
+
// Add other archive mime types here
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
return archiveMimeTypes.has(mimeType);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
private getDecompressionStream(
|
|
34
|
+
mimeTypeArg: plugins.fileType.FileTypeResult['mime']
|
|
35
|
+
): plugins.stream.Transform | plugins.stream.Duplex | plugins.tarStream.Extract {
|
|
36
|
+
switch (mimeTypeArg) {
|
|
37
|
+
case 'application/gzip':
|
|
38
|
+
return this.smartArchiveRef.gzipTools.getDecompressionStream();
|
|
39
|
+
case 'application/x-bzip2':
|
|
40
|
+
return this.smartArchiveRef.bzip2Tools.getDecompressionStream(); // replace with your own bzip2 decompression stream
|
|
41
|
+
case 'application/x-tar':
|
|
42
|
+
return this.smartArchiveRef.tarTools.getDecompressionStream(); // replace with your own tar decompression stream
|
|
43
|
+
default:
|
|
44
|
+
// Handle unsupported formats or no decompression needed
|
|
45
|
+
return new plugins.smartstream.PassThrough();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public getAnalyzedStream() {
|
|
50
|
+
let firstRun = true;
|
|
51
|
+
const resultStream = new plugins.smartstream.PassThrough();
|
|
52
|
+
const analyzerstream = new plugins.smartstream.SmartDuplex<Buffer, IAnalyzedResult>({
|
|
53
|
+
readableObjectMode: true,
|
|
54
|
+
writeAndTransformFunction: async (chunkArg: Buffer, streamtools) => {
|
|
55
|
+
const fileType = await plugins.fileType.fileTypeFromBuffer(chunkArg);
|
|
56
|
+
const decompressionStream = this.getDecompressionStream(fileType.mime as any);
|
|
57
|
+
resultStream.push(chunkArg);
|
|
58
|
+
if (firstRun) {
|
|
59
|
+
firstRun = false;
|
|
60
|
+
const result: IAnalyzedResult = {
|
|
61
|
+
fileType,
|
|
62
|
+
isArchive: await this.mimeTypeIsArchive(fileType.mime),
|
|
63
|
+
resultStream,
|
|
64
|
+
decompressionStream,
|
|
65
|
+
};
|
|
66
|
+
streamtools.push(result);
|
|
67
|
+
streamtools.push(null);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
return analyzerstream;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { SmartArchive } from './classes.smartarchive.js';
|
|
2
|
+
import * as plugins from './plugins.js';
|
|
3
|
+
|
|
4
|
+
export class DecompressBzip2Transform extends plugins.stream.Transform {
|
|
5
|
+
private bzip2Decompressor: plugins.stream.Transform;
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
// Initialize the bzip2 decompressor once here
|
|
10
|
+
this.bzip2Decompressor = plugins.unbzip2Stream();
|
|
11
|
+
this.bzip2Decompressor.on('data', (data: Buffer) => {
|
|
12
|
+
// When data is decompressed, push it to the stream
|
|
13
|
+
this.push(data);
|
|
14
|
+
});
|
|
15
|
+
this.bzip2Decompressor.on('error', (err) => {
|
|
16
|
+
// If an error occurs, emit it on this stream
|
|
17
|
+
this.emit('error', err);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback) {
|
|
22
|
+
// Pass the chunk directly to the decompressor
|
|
23
|
+
// The decompressor will handle the state across chunks
|
|
24
|
+
this.bzip2Decompressor.write(chunk);
|
|
25
|
+
callback();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_flush(callback: plugins.stream.TransformCallback) {
|
|
29
|
+
// When the stream is ending, end the decompressor stream as well
|
|
30
|
+
this.bzip2Decompressor.end();
|
|
31
|
+
callback();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class Bzip2Tools {
|
|
36
|
+
smartArchiveRef: SmartArchive;
|
|
37
|
+
|
|
38
|
+
constructor(smartArchiveRefArg: SmartArchive) {
|
|
39
|
+
this.smartArchiveRef = smartArchiveRefArg;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getDecompressionStream() {
|
|
43
|
+
return new DecompressBzip2Transform();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { SmartArchive } from './classes.smartarchive.js';
|
|
2
|
+
import * as plugins from './plugins.js'
|
|
3
|
+
|
|
4
|
+
// This class wraps fflate's gunzip in a Node.js Transform stream
|
|
5
|
+
export class CompressGunzipTransform extends plugins.stream.Transform {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback) {
|
|
11
|
+
plugins.fflate.gunzip(chunk, (err, decompressed) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
callback(err);
|
|
14
|
+
} else {
|
|
15
|
+
this.push(decompressed);
|
|
16
|
+
callback();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// DecompressGunzipTransform class that extends the Node.js Transform stream to
|
|
23
|
+
// create a stream that decompresses GZip-compressed data using fflate's gunzip function
|
|
24
|
+
export class DecompressGunzipTransform extends plugins.stream.Transform {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: plugins.stream.TransformCallback) {
|
|
30
|
+
// Use fflate's gunzip function to decompress the chunk
|
|
31
|
+
plugins.fflate.gunzip(chunk, (err, decompressed) => {
|
|
32
|
+
if (err) {
|
|
33
|
+
// If an error occurs during decompression, pass the error to the callback
|
|
34
|
+
callback(err);
|
|
35
|
+
} else {
|
|
36
|
+
// If decompression is successful, push the decompressed data into the stream
|
|
37
|
+
this.push(decompressed);
|
|
38
|
+
callback();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export class GzipTools {
|
|
46
|
+
smartArchiveRef: SmartArchive;
|
|
47
|
+
|
|
48
|
+
constructor(smartArchiveRefArg: SmartArchive) {
|
|
49
|
+
this.smartArchiveRef = smartArchiveRefArg;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public getCompressionStream() {
|
|
53
|
+
return new CompressGunzipTransform();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public getDecompressionStream() {
|
|
57
|
+
return new DecompressGunzipTransform();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import * as paths from './paths.js';
|
|
3
|
+
|
|
4
|
+
import { GzipTools } from './classes.gziptools.js';
|
|
5
|
+
import { TarTools } from './classes.tartools.js';
|
|
6
|
+
import { Bzip2Tools } from './classes.bzip2tools.js';
|
|
7
|
+
|
|
8
|
+
import { ArchiveAnalyzer, type IAnalyzedResult } from './classes.archiveanalyzer.js';
|
|
9
|
+
|
|
10
|
+
import type { from } from '@push.rocks/smartrx/dist_ts/smartrx.plugins.rxjs.js';
|
|
11
|
+
|
|
12
|
+
export class SmartArchive {
|
|
13
|
+
// STATIC
|
|
14
|
+
public static async fromArchiveUrl(urlArg: string): Promise<SmartArchive> {
|
|
15
|
+
const smartArchiveInstance = new SmartArchive();
|
|
16
|
+
smartArchiveInstance.sourceUrl = urlArg;
|
|
17
|
+
return smartArchiveInstance;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static async fromArchiveFile(filePathArg: string): Promise<SmartArchive> {
|
|
21
|
+
const smartArchiveInstance = new SmartArchive();
|
|
22
|
+
smartArchiveInstance.sourceFilePath = filePathArg;
|
|
23
|
+
return smartArchiveInstance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static async fromArchiveStream(
|
|
27
|
+
streamArg: plugins.stream.Readable | plugins.stream.Duplex | plugins.stream.Transform
|
|
28
|
+
): Promise<SmartArchive> {
|
|
29
|
+
const smartArchiveInstance = new SmartArchive();
|
|
30
|
+
smartArchiveInstance.sourceStream = streamArg;
|
|
31
|
+
return smartArchiveInstance;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// INSTANCE
|
|
35
|
+
public tarTools = new TarTools(this);
|
|
36
|
+
public gzipTools = new GzipTools(this);
|
|
37
|
+
public bzip2Tools = new Bzip2Tools(this);
|
|
38
|
+
public archiveAnalyzer = new ArchiveAnalyzer(this);
|
|
39
|
+
|
|
40
|
+
public sourceUrl: string;
|
|
41
|
+
public sourceFilePath: string;
|
|
42
|
+
public sourceStream: plugins.stream.Readable | plugins.stream.Duplex | plugins.stream.Transform;
|
|
43
|
+
|
|
44
|
+
public archiveName: string;
|
|
45
|
+
public singleFileMode: boolean = false;
|
|
46
|
+
|
|
47
|
+
public addedDirectories: string[] = [];
|
|
48
|
+
public addedFiles: (plugins.smartfile.SmartFile | plugins.smartfile.StreamFile)[] = [];
|
|
49
|
+
public addedUrls: string[] = [];
|
|
50
|
+
|
|
51
|
+
constructor() {}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* gets the original archive stream
|
|
55
|
+
*/
|
|
56
|
+
public async getArchiveStream() {
|
|
57
|
+
if (this.sourceStream) {
|
|
58
|
+
return this.sourceStream;
|
|
59
|
+
}
|
|
60
|
+
if (this.sourceUrl) {
|
|
61
|
+
const urlStream = await plugins.smartrequest.getStream(this.sourceUrl);
|
|
62
|
+
return urlStream;
|
|
63
|
+
}
|
|
64
|
+
if (this.sourceFilePath) {
|
|
65
|
+
const fileStream = plugins.smartfile.fs.toReadStream(this.sourceFilePath);
|
|
66
|
+
return fileStream;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public async exportToTarGzStream() {
|
|
71
|
+
const tarPackStream = await this.tarTools.getPackStream();
|
|
72
|
+
const gzipStream = await this.gzipTools.getCompressionStream();
|
|
73
|
+
// const archiveStream = tarPackStream.pipe(gzipStream);
|
|
74
|
+
// return archiveStream;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async exportToFs(targetDir: string): Promise<void> {}
|
|
78
|
+
|
|
79
|
+
public async exportToStreamOfStreamFiles() {
|
|
80
|
+
const streamFileIntake = new plugins.smartstream.StreamIntake<plugins.smartfile.StreamFile>({
|
|
81
|
+
objectMode: true,
|
|
82
|
+
});
|
|
83
|
+
const archiveStream = await this.getArchiveStream();
|
|
84
|
+
const createAnalyzedStream = () => this.archiveAnalyzer.getAnalyzedStream();
|
|
85
|
+
|
|
86
|
+
// lets create a function that can be called multiple times to unpack layers of archives
|
|
87
|
+
const createUnpackStream = () =>
|
|
88
|
+
plugins.smartstream.createTransformFunction<IAnalyzedResult, any>(
|
|
89
|
+
async (analyzedResultChunk) => {
|
|
90
|
+
if (analyzedResultChunk.fileType.mime === 'application/x-tar') {
|
|
91
|
+
(analyzedResultChunk.decompressionStream as plugins.tarStream.Extract).on(
|
|
92
|
+
'entry',
|
|
93
|
+
async (header, stream, next) => {
|
|
94
|
+
const streamfile = plugins.smartfile.StreamFile.fromStream(stream, header.name);
|
|
95
|
+
streamFileIntake.push(streamfile);
|
|
96
|
+
stream.on('end', function () {
|
|
97
|
+
next(); // ready for next entry
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
analyzedResultChunk.resultStream.pipe(analyzedResultChunk.decompressionStream);
|
|
102
|
+
} else if (analyzedResultChunk.isArchive && analyzedResultChunk.decompressionStream) {
|
|
103
|
+
analyzedResultChunk.resultStream
|
|
104
|
+
.pipe(analyzedResultChunk.decompressionStream)
|
|
105
|
+
.pipe(createAnalyzedStream())
|
|
106
|
+
.pipe(createUnpackStream());
|
|
107
|
+
} else {
|
|
108
|
+
const streamFile = plugins.smartfile.StreamFile.fromStream(
|
|
109
|
+
analyzedResultChunk.resultStream,
|
|
110
|
+
analyzedResultChunk.fileType.ext
|
|
111
|
+
);
|
|
112
|
+
streamFileIntake.push(streamFile);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
archiveStream.pipe(createAnalyzedStream()).pipe(createUnpackStream());
|
|
118
|
+
return streamFileIntake;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SmartArchive } from './classes.smartarchive.js';
|
|
2
|
+
import * as plugins from './plugins.js';
|
|
3
|
+
|
|
4
|
+
export class TarTools {
|
|
5
|
+
smartArchiveRef: SmartArchive;
|
|
6
|
+
|
|
7
|
+
constructor(smartArchiveRefArg: SmartArchive) {
|
|
8
|
+
this.smartArchiveRef = smartArchiveRefArg;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// packing
|
|
12
|
+
public addFileToPack(pack: plugins.tarStream.Pack, fileName: string, content: string | Buffer) {
|
|
13
|
+
return new Promise<void>((resolve, reject) => {
|
|
14
|
+
const entry = pack.entry({ name: fileName, size: content.length }, (err: Error) => {
|
|
15
|
+
if (err) {
|
|
16
|
+
reject(err);
|
|
17
|
+
} else {
|
|
18
|
+
resolve();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
entry.write(content);
|
|
23
|
+
entry.end();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async getPackStream() {
|
|
28
|
+
const pack = plugins.tarStream.pack();
|
|
29
|
+
return pack;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// extracting
|
|
33
|
+
getDecompressionStream() {
|
|
34
|
+
return plugins.tarStream.extract();
|
|
35
|
+
}
|
|
36
|
+
}
|
package/ts/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './classes.smartarchive.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// node native scope
|
|
2
2
|
import * as path from 'path';
|
|
3
|
+
import * as stream from 'stream';
|
|
3
4
|
|
|
4
|
-
export { path };
|
|
5
|
+
export { path, stream };
|
|
5
6
|
|
|
6
7
|
// @pushrocks scope
|
|
7
8
|
import * as smartfile from '@push.rocks/smartfile';
|
|
@@ -11,14 +12,14 @@ import * as smartrequest from '@push.rocks/smartrequest';
|
|
|
11
12
|
import * as smartunique from '@push.rocks/smartunique';
|
|
12
13
|
import * as smartstream from '@push.rocks/smartstream';
|
|
13
14
|
import * as smartrx from '@push.rocks/smartrx';
|
|
15
|
+
import * as smarturl from '@push.rocks/smarturl';
|
|
14
16
|
|
|
15
|
-
export { smartfile, smartpath, smartpromise, smartrequest, smartunique, smartstream, smartrx };
|
|
17
|
+
export { smartfile, smartpath, smartpromise, smartrequest, smartunique, smartstream, smartrx, smarturl };
|
|
16
18
|
|
|
17
19
|
// third party scope
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
import tar from 'tar';
|
|
20
|
+
import * as fileType from 'file-type';
|
|
21
|
+
import * as fflate from 'fflate';
|
|
22
22
|
import tarStream from 'tar-stream';
|
|
23
|
+
import unbzip2Stream from 'unbzip2-stream';
|
|
23
24
|
|
|
24
|
-
export {
|
|
25
|
+
export { fileType, fflate, tarStream, unbzip2Stream };
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import * as plugins from './smartarchive.plugins.js';
|
|
2
|
-
import * as paths from './smartarchive.paths.js';
|
|
3
|
-
|
|
4
|
-
export class SmartArchive {
|
|
5
|
-
constructor() {}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* extracts an archive from a given url
|
|
9
|
-
*/
|
|
10
|
-
public async extractArchiveFromUrlToFs(urlArg: string, targetDir: string) {
|
|
11
|
-
const parsedPath = plugins.path.parse(urlArg);
|
|
12
|
-
const uniqueFileName = plugins.smartunique.uni() + parsedPath.ext;
|
|
13
|
-
plugins.smartfile.fs.ensureDir(paths.nogitDir); // TODO: totally remove caching needs
|
|
14
|
-
const downloadPath = plugins.path.join(paths.nogitDir, uniqueFileName);
|
|
15
|
-
const downloadedArchive = (await plugins.smartrequest.getBinary(urlArg)).body;
|
|
16
|
-
await plugins.smartfile.memory.toFs(downloadedArchive, downloadPath);
|
|
17
|
-
await this.extractArchiveFromFilePathToFs(downloadPath, targetDir);
|
|
18
|
-
await plugins.smartfile.fs.remove(downloadPath);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* extracts an archive from a given filePath on disk
|
|
23
|
-
* @param filePathArg
|
|
24
|
-
* @param targetDirArg
|
|
25
|
-
*/
|
|
26
|
-
public async extractArchiveFromFilePathToFs(filePathArg: string, targetDirArg: string) {
|
|
27
|
-
console.log(`extracting ${filePathArg}`);
|
|
28
|
-
const done = plugins.smartpromise.defer();
|
|
29
|
-
filePathArg = plugins.smartpath.transform.makeAbsolute(filePathArg);
|
|
30
|
-
targetDirArg = plugins.smartpath.transform.makeAbsolute(targetDirArg);
|
|
31
|
-
const readableStream = plugins.smartfile.fsStream.createReadStream(filePathArg);
|
|
32
|
-
const extractPipeStop = plugins.tarStream.extract();
|
|
33
|
-
extractPipeStop.on('entry', async (header, stream, next) => {
|
|
34
|
-
const targetFilePath = plugins.path.join(targetDirArg, header.name);
|
|
35
|
-
const parsedPath = plugins.path.parse(targetFilePath);
|
|
36
|
-
await plugins.smartfile.fs.ensureDir(parsedPath.dir);
|
|
37
|
-
const writeStream = plugins.smartfile.fsStream.createWriteStream(targetFilePath);
|
|
38
|
-
stream.pipe(writeStream);
|
|
39
|
-
stream.on('end', () => {
|
|
40
|
-
console.log(`extracted ${header.name}`);
|
|
41
|
-
next();
|
|
42
|
-
});
|
|
43
|
-
stream.resume();
|
|
44
|
-
});
|
|
45
|
-
extractPipeStop.on('finish', () => {
|
|
46
|
-
console.log(`Sucessfully extracted ${filePathArg}!`);
|
|
47
|
-
done.resolve();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// lets run the stream
|
|
51
|
-
readableStream.pipe(plugins.gunzipMaybe()).pipe(extractPipeStop);
|
|
52
|
-
await done.promise;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* extracts to Observable
|
|
57
|
-
* where the Observable is emitting smartfiles
|
|
58
|
-
*/
|
|
59
|
-
public async extractArchiveFromBufferToObservable(
|
|
60
|
-
bufferArg: Buffer
|
|
61
|
-
): Promise<plugins.smartrx.rxjs.ReplaySubject<plugins.smartfile.Smartfile>> {
|
|
62
|
-
const { intake, replaySubject } = this.extractArchiveWithIntakeAndReplaySubject();
|
|
63
|
-
intake.pushData(bufferArg);
|
|
64
|
-
intake.signalEnd();
|
|
65
|
-
return replaySubject;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
extractArchiveWithIntakeAndReplaySubject() {
|
|
69
|
-
const intake = new plugins.smartstream.StreamIntake<Buffer>();
|
|
70
|
-
const replaySubject = new plugins.smartrx.rxjs.ReplaySubject<plugins.smartfile.Smartfile>();
|
|
71
|
-
const readableStream = intake.getReadableStream();
|
|
72
|
-
const extractPipeStop = plugins.tarStream.extract();
|
|
73
|
-
extractPipeStop.on('entry', (header, stream, next) => {
|
|
74
|
-
let fileBuffer: Buffer;
|
|
75
|
-
stream.on('data', (chunkArg) => {
|
|
76
|
-
if (!fileBuffer) {
|
|
77
|
-
fileBuffer = chunkArg;
|
|
78
|
-
} else {
|
|
79
|
-
fileBuffer = Buffer.concat([fileBuffer, chunkArg]);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
stream.on('end', () => {
|
|
83
|
-
replaySubject.next(
|
|
84
|
-
new plugins.smartfile.Smartfile({
|
|
85
|
-
base: null, // no working directory for this one
|
|
86
|
-
contentBuffer: fileBuffer,
|
|
87
|
-
path: `${header.name}`,
|
|
88
|
-
})
|
|
89
|
-
);
|
|
90
|
-
next();
|
|
91
|
-
});
|
|
92
|
-
stream.resume();
|
|
93
|
-
});
|
|
94
|
-
extractPipeStop.on('finish', () => {
|
|
95
|
-
replaySubject.complete();
|
|
96
|
-
});
|
|
97
|
-
// lets run the stream
|
|
98
|
-
readableStream.pipe(plugins.gunzipMaybe()).pipe(extractPipeStop);
|
|
99
|
-
return {
|
|
100
|
-
intake,
|
|
101
|
-
replaySubject,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* extracts to Observable
|
|
107
|
-
*/
|
|
108
|
-
public async extractArchiveFromUrlToObservable(
|
|
109
|
-
urlArg: string
|
|
110
|
-
): Promise<plugins.smartrx.rxjs.ReplaySubject<plugins.smartfile.Smartfile>> {
|
|
111
|
-
const response = await plugins.smartrequest.getBinary(urlArg);
|
|
112
|
-
const replaySubject = this.extractArchiveFromBufferToObservable(response.body);
|
|
113
|
-
return replaySubject;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// TODO
|
|
117
|
-
public async extractArchiveFromUrlToStream() {}
|
|
118
|
-
|
|
119
|
-
// TODO
|
|
120
|
-
public async extractArchiveFromFilePathToStream() {}
|
|
121
|
-
|
|
122
|
-
// TODO
|
|
123
|
-
public async extractArchiveFromStreamToStream() {}
|
|
124
|
-
|
|
125
|
-
// TODO
|
|
126
|
-
public async packFromStreamToStream() {}
|
|
127
|
-
|
|
128
|
-
// TODO
|
|
129
|
-
public async packFromDirPathToStream() {}
|
|
130
|
-
|
|
131
|
-
// TODO
|
|
132
|
-
public async packFromDirPathToFs() {}
|
|
133
|
-
}
|