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) => {