Compare commits

..

4 Commits

Author SHA1 Message Date
e3ab98751d 4.0.2 2023-11-06 19:46:03 +01:00
401150bd10 fix(core): update 2023-11-06 19:46:02 +01:00
77e75ee0d9 4.0.1 2023-11-06 19:38:37 +01:00
2f33672374 fix(core): update 2023-11-06 19:38:36 +01:00
4 changed files with 28 additions and 19 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartarchive",
"version": "4.0.0",
"version": "4.0.2",
"description": "work with archives",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",

View File

@ -35,21 +35,7 @@ tap.test('should extract existing files on disk', async () => {
const testSmartarchive = await smartarchive.SmartArchive.fromArchiveUrl(
'https://verdaccio.lossless.digital/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz'
);
const streamfileStream = await testSmartarchive.exportToStreamOfStreamFiles();
streamfileStream.pipe(new plugins.smartstream.SmartDuplex({
objectMode: true,
writeAndTransformFunction: async (chunkArg: plugins.smartfile.StreamFile, streamtools) => {
console.log(chunkArg.relativeFilePath);
const streamFile = chunkArg;
const readStream = await streamFile.createReadStream();
const writePath = plugins.path.join(testPaths.nogitDir + streamFile.relativeFilePath);
const dir = plugins.path.parse(writePath).dir;
await plugins.smartfile.fs.ensureDir(plugins.path.dirname(dir));
const writeStream = plugins.smartfile.fsStream.createWriteStream(writePath);
readStream.pipe(writeStream);
},
}));
const streamfileStream = await testSmartarchive.exportToFs(testPaths.nogitDir);
});
tap.start();

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartarchive',
version: '4.0.0',
version: '4.0.2',
description: 'work with archives'
}

View File

@ -74,7 +74,26 @@ export class SmartArchive {
// return archiveStream;
}
public async exportToFs(targetDir: string): Promise<void> {}
public async exportToFs(targetDir: string): Promise<void> {
const done = plugins.smartpromise.defer<void>();
const streamFileStream = await this.exportToStreamOfStreamFiles();
streamFileStream.pipe(new plugins.smartstream.SmartDuplex({
objectMode: true,
writeAndTransformFunction: async (chunkArg: plugins.smartfile.StreamFile, streamtools) => {
console.log(chunkArg.relativeFilePath);
const streamFile = chunkArg;
const readStream = await streamFile.createReadStream();
const writePath = plugins.path.join(targetDir + streamFile.relativeFilePath);
const dir = plugins.path.parse(writePath).dir;
await plugins.smartfile.fs.ensureDir(plugins.path.dirname(dir));
const writeStream = plugins.smartfile.fsStream.createWriteStream(writePath);
readStream.pipe(writeStream).end(() => {
done.resolve();
});
},
}));
return done.promise;
}
public async exportToStreamOfStreamFiles() {
const streamFileIntake = new plugins.smartstream.StreamIntake<plugins.smartfile.StreamFile>({
@ -88,7 +107,8 @@ export class SmartArchive {
plugins.smartstream.createTransformFunction<IAnalyzedResult, any>(
async (analyzedResultChunk) => {
if (analyzedResultChunk.fileType.mime === 'application/x-tar') {
(analyzedResultChunk.decompressionStream as plugins.tarStream.Extract).on(
const tarStream = analyzedResultChunk.decompressionStream as plugins.tarStream.Extract;
tarStream.on(
'entry',
async (header, stream, next) => {
const streamfile = plugins.smartfile.StreamFile.fromStream(stream, header.name);
@ -98,6 +118,9 @@ export class SmartArchive {
});
}
);
tarStream.on('finish', function () {
streamFileIntake.signalEnd();
})
analyzedResultChunk.resultStream.pipe(analyzedResultChunk.decompressionStream);
} else if (analyzedResultChunk.isArchive && analyzedResultChunk.decompressionStream) {
analyzedResultChunk.resultStream