From 6500b7a8c73423dbd938d806e02d3311a5350da0 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 16 Sep 2018 02:57:25 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20Offload=20file=20extraction=20to?= =?UTF-8?q?=20patch-installer=20instead=20of=20piping=20it=20back?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/getPatch.ts | 10 +++------- src/ssn/installation/launch.ts | 13 ++++++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index b74b41b..affb36a 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -85,12 +85,9 @@ export default async function getPatch({ product, from, to, sourceDirectory, tar const outputName = path.join(targetDir, file.name); const outputNameTemp = path.join(targetDir, `${file.name}.tmp`); await createDirRecursively(path.dirname(outputNameTemp)); - const outputStream = fs.createWriteStream(outputNameTemp); //start installation - await launch(diskFilenames[file.diskNumberStart], file.offset, file.compressedSize, file.decryptionKeys, undefined, outputStream); - - outputStream.close(); + await launch(diskFilenames[file.diskNumberStart], file.offset, file.compressedSize, file.decryptionKeys, undefined, outputNameTemp); fs.rename(outputNameTemp, outputName, (renameError) => { if (renameError) { @@ -108,12 +105,11 @@ export default async function getPatch({ product, from, to, sourceDirectory, tar const outputName = path.join(targetDir, file.name); const outputNameTemp = path.join(targetDir, `${file.name}.tmp`); - //create file write stream + //create directory where file is await createDirRecursively(path.dirname(outputNameTemp)); - const outputStream = fs.createWriteStream(outputNameTemp); //start installation - await launch(diskFilenames[file.diskNumberStart], file.offset, file.compressedSize, file.decryptionKeys, sourceFile, outputStream); + await launch(diskFilenames[file.diskNumberStart], file.offset, file.compressedSize, file.decryptionKeys, sourceFile, outputNameTemp); //clean up: delete source file if necessary, and remove .tmp file extension if (sourceDir === targetDir) { diff --git a/src/ssn/installation/launch.ts b/src/ssn/installation/launch.ts index 35e764d..53ae875 100644 --- a/src/ssn/installation/launch.ts +++ b/src/ssn/installation/launch.ts @@ -10,7 +10,7 @@ export default function launchProcess( compressedSize: number, decryptionKeys: [number, number, number] | undefined, previousFile: string | undefined, - outputStream: fs.WriteStream, + output: string | fs.WriteStream, ) { return new Promise((resolve, reject) => { const parameters = [ @@ -24,11 +24,18 @@ export default function launchProcess( if (previousFile !== undefined) { parameters.push('--previous', previousFile); } + if (typeof output === 'string') { + parameters.push('--target', output); + } const spawnedProcess = childProcess.spawn(processPath, parameters.map((value) => value.toString(), { cwd: '.' })); - spawnedProcess.stdout.pipe(outputStream); - spawnedProcess.stdout.on('end', resolve); + if (typeof output === 'string') { + //TODO: output stdout to console just in case for error logging + } else { + spawnedProcess.stdout.pipe(output); + spawnedProcess.stdout.on('end', resolve); + } spawnedProcess.stderr.setEncoding('utf8'); spawnedProcess.stderr.on('data', (error) => {