Bundle install: Only use stdin for streaming

This commit is contained in:
Henry Mercer 2024-10-22 17:32:33 +01:00
parent b35b023d9b
commit 8c3a732e36
3 changed files with 16 additions and 15 deletions

View file

@ -125,23 +125,19 @@ export async function extract(
"Could not determine tar version, which is required to extract a Zstandard archive.",
);
}
return await extractTarZst(
fs.createReadStream(tarPath),
tarVersion,
logger,
);
return await extractTarZst(tarPath, tarVersion, logger);
}
}
/**
* Extract a compressed tar archive
*
* @param file path to the tar
* @param tar tar stream, or path to the tar
* @param dest destination directory. Optional.
* @returns path to the destination directory
*/
export async function extractTarZst(
tarStream: stream.Readable,
tar: stream.Readable | string,
tarVersion: TarVersion,
logger: Logger,
): Promise<string> {
@ -157,7 +153,7 @@ export async function extractTarZst(
args.push("--overwrite");
}
args.push("-f", "-", "-C", dest);
args.push("-f", tar instanceof stream.Readable ? "-" : tar, "-C", dest);
process.stdout.write(`[command]tar ${args.join(" ")}\n`);
@ -175,7 +171,9 @@ export async function extractTarZst(
process.stdout.write(data);
});
tarStream.pipe(tarProcess.stdin);
if (tar instanceof stream.Readable) {
tar.pipe(tarProcess.stdin);
}
await new Promise<void>((resolve, reject) => {
tarProcess.on("exit", (code) => {