🐎 Offload file extraction to patch-installer instead of piping it back
This commit is contained in:
parent
f074739579
commit
6500b7a8c7
2 changed files with 13 additions and 10 deletions
|
@ -85,12 +85,9 @@ export default async function getPatch({ product, from, to, sourceDirectory, tar
|
||||||
const outputName = path.join(targetDir, file.name);
|
const outputName = path.join(targetDir, file.name);
|
||||||
const outputNameTemp = path.join(targetDir, `${file.name}.tmp`);
|
const outputNameTemp = path.join(targetDir, `${file.name}.tmp`);
|
||||||
await createDirRecursively(path.dirname(outputNameTemp));
|
await createDirRecursively(path.dirname(outputNameTemp));
|
||||||
const outputStream = fs.createWriteStream(outputNameTemp);
|
|
||||||
|
|
||||||
//start installation
|
//start installation
|
||||||
await launch(diskFilenames[file.diskNumberStart], file.offset, file.compressedSize, file.decryptionKeys, undefined, outputStream);
|
await launch(diskFilenames[file.diskNumberStart], file.offset, file.compressedSize, file.decryptionKeys, undefined, outputNameTemp);
|
||||||
|
|
||||||
outputStream.close();
|
|
||||||
|
|
||||||
fs.rename(outputNameTemp, outputName, (renameError) => {
|
fs.rename(outputNameTemp, outputName, (renameError) => {
|
||||||
if (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 outputName = path.join(targetDir, file.name);
|
||||||
const outputNameTemp = path.join(targetDir, `${file.name}.tmp`);
|
const outputNameTemp = path.join(targetDir, `${file.name}.tmp`);
|
||||||
|
|
||||||
//create file write stream
|
//create directory where file is
|
||||||
await createDirRecursively(path.dirname(outputNameTemp));
|
await createDirRecursively(path.dirname(outputNameTemp));
|
||||||
const outputStream = fs.createWriteStream(outputNameTemp);
|
|
||||||
|
|
||||||
//start installation
|
//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
|
//clean up: delete source file if necessary, and remove .tmp file extension
|
||||||
if (sourceDir === targetDir) {
|
if (sourceDir === targetDir) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ export default function launchProcess(
|
||||||
compressedSize: number,
|
compressedSize: number,
|
||||||
decryptionKeys: [number, number, number] | undefined,
|
decryptionKeys: [number, number, number] | undefined,
|
||||||
previousFile: string | undefined,
|
previousFile: string | undefined,
|
||||||
outputStream: fs.WriteStream,
|
output: string | fs.WriteStream,
|
||||||
) {
|
) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const parameters = [
|
const parameters = [
|
||||||
|
@ -24,11 +24,18 @@ export default function launchProcess(
|
||||||
if (previousFile !== undefined) {
|
if (previousFile !== undefined) {
|
||||||
parameters.push('--previous', previousFile);
|
parameters.push('--previous', previousFile);
|
||||||
}
|
}
|
||||||
|
if (typeof output === 'string') {
|
||||||
|
parameters.push('--target', output);
|
||||||
|
}
|
||||||
|
|
||||||
const spawnedProcess = childProcess.spawn(processPath, parameters.map((value) => value.toString(), { cwd: '.' }));
|
const spawnedProcess = childProcess.spawn(processPath, parameters.map((value) => value.toString(), { cwd: '.' }));
|
||||||
|
|
||||||
spawnedProcess.stdout.pipe(outputStream);
|
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.stdout.on('end', resolve);
|
||||||
|
}
|
||||||
|
|
||||||
spawnedProcess.stderr.setEncoding('utf8');
|
spawnedProcess.stderr.setEncoding('utf8');
|
||||||
spawnedProcess.stderr.on('data', (error) => {
|
spawnedProcess.stderr.on('data', (error) => {
|
||||||
|
|
Loading…
Reference in a new issue