Ensure destination directory exists when streaming extraction

This commit is contained in:
Henry Mercer
2024-12-03 15:42:51 +00:00
parent d5bcf48469
commit b2a4442810
6 changed files with 15 additions and 4 deletions

View File

@@ -175,7 +175,9 @@ export async function extractTarZst(
if (tar instanceof stream.Readable) {
tar.pipe(tarProcess.stdin).on("error", (err) => {
reject(new Error(`Error while piping tar stream: ${err}`));
reject(
new Error(`Error while downloading and extracting tar: ${err}`),
);
});
}

View File

@@ -183,6 +183,10 @@ async function downloadAndExtractZstdWithStreaming(
tarVersion: tar.TarVersion,
logger: Logger,
): Promise<void> {
// Ensure destination exists
fs.mkdirSync(dest, { recursive: true });
// Add User-Agent header and Authorization header if provided.
headers = Object.assign(
{ "User-Agent": "CodeQL Action" },
authorization ? { authorization } : {},
@@ -193,6 +197,7 @@ async function downloadAndExtractZstdWithStreaming(
codeqlURL,
{
headers,
// Increase the high water mark to improve performance.
highWaterMark: STREAMING_HIGH_WATERMARK_BYTES,
} as unknown as RequestOptions,
(r) => resolve(r),