feat(classes.smartarchive): Support URL streams, recursive archive unpacking and filesystem export; improve ZIP/GZIP/BZIP2 robustness; CI and package metadata updates
This commit is contained in:
@@ -5,7 +5,10 @@ export interface IAnalyzedResult {
|
||||
fileType: plugins.fileType.FileTypeResult;
|
||||
isArchive: boolean;
|
||||
resultStream: plugins.smartstream.SmartDuplex;
|
||||
decompressionStream: plugins.stream.Transform | plugins.stream.Duplex | plugins.tarStream.Extract;
|
||||
decompressionStream:
|
||||
| plugins.stream.Transform
|
||||
| plugins.stream.Duplex
|
||||
| plugins.tarStream.Extract;
|
||||
}
|
||||
|
||||
export class ArchiveAnalyzer {
|
||||
@@ -25,14 +28,15 @@ export class ArchiveAnalyzer {
|
||||
'application/x-bzip2',
|
||||
// Add other archive mime types here
|
||||
]);
|
||||
|
||||
|
||||
return archiveMimeTypes.has(mimeType);
|
||||
}
|
||||
|
||||
|
||||
private async getDecompressionStream(
|
||||
mimeTypeArg: plugins.fileType.FileTypeResult['mime']
|
||||
): Promise<plugins.stream.Transform | plugins.stream.Duplex | plugins.tarStream.Extract> {
|
||||
mimeTypeArg: plugins.fileType.FileTypeResult['mime'],
|
||||
): Promise<
|
||||
plugins.stream.Transform | plugins.stream.Duplex | plugins.tarStream.Extract
|
||||
> {
|
||||
switch (mimeTypeArg) {
|
||||
case 'application/gzip':
|
||||
return this.smartArchiveRef.gzipTools.getDecompressionStream();
|
||||
@@ -51,13 +55,18 @@ export class ArchiveAnalyzer {
|
||||
public getAnalyzedStream() {
|
||||
let firstRun = true;
|
||||
const resultStream = plugins.smartstream.createPassThrough();
|
||||
const analyzerstream = new plugins.smartstream.SmartDuplex<Buffer, IAnalyzedResult>({
|
||||
const analyzerstream = new plugins.smartstream.SmartDuplex<
|
||||
Buffer,
|
||||
IAnalyzedResult
|
||||
>({
|
||||
readableObjectMode: true,
|
||||
writeFunction: async (chunkArg: Buffer, streamtools) => {
|
||||
if (firstRun) {
|
||||
firstRun = false;
|
||||
const fileType = await plugins.fileType.fileTypeFromBuffer(chunkArg);
|
||||
const decompressionStream = await this.getDecompressionStream(fileType?.mime as any);
|
||||
const decompressionStream = await this.getDecompressionStream(
|
||||
fileType?.mime as any,
|
||||
);
|
||||
/**
|
||||
* analyzed stream emits once with this object
|
||||
*/
|
||||
@@ -75,7 +84,7 @@ export class ArchiveAnalyzer {
|
||||
finalFunction: async (tools) => {
|
||||
resultStream.push(null);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
return analyzerstream;
|
||||
}
|
||||
|
Reference in New Issue
Block a user