diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 5286ce0..22b2739 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartarchive', - version: '4.0.0', + version: '4.0.1', description: 'work with archives' } diff --git a/ts/classes.smartarchive.ts b/ts/classes.smartarchive.ts index 5e589f3..f8383ec 100644 --- a/ts/classes.smartarchive.ts +++ b/ts/classes.smartarchive.ts @@ -74,7 +74,26 @@ export class SmartArchive { // return archiveStream; } - public async exportToFs(targetDir: string): Promise {} + public async exportToFs(targetDir: string): Promise { + const done = plugins.smartpromise.defer(); + 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({