Skip to content

Commit

Permalink
Bundle install: Only use stdin for streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Oct 22, 2024
1 parent b35b023 commit 8c3a732
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
13 changes: 8 additions & 5 deletions lib/tar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tar.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions src/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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`);

Expand All @@ -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) => {
Expand Down

0 comments on commit 8c3a732

Please sign in to comment.