Close stream after use

This commit is contained in:
Robert 2023-01-09 11:00:43 +00:00
parent e8f7169839
commit a9337bc304
3 changed files with 43 additions and 31 deletions

33
lib/database-upload.js generated
View file

@ -50,19 +50,26 @@ async function uploadDatabases(repositoryNwo, config, apiDetails, logger) {
// noting that it's the API's job to validate that the contents is acceptable.
// This API method is available to anyone with write access to the repo.
const bundledDb = await (0, util_1.bundleDb)(config, language, codeql, language);
await client.request(`POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name`, {
owner: repositoryNwo.owner,
repo: repositoryNwo.repo,
language,
name: `${language}-database`,
data: fs.createReadStream(bundledDb),
headers: {
authorization: `token ${apiDetails.auth}`,
"Content-Type": "application/zip",
"Content-Length": fs.statSync(bundledDb).size,
},
});
logger.debug(`Successfully uploaded database for ${language}`);
const bundledDbSize = fs.statSync(bundledDb).size;
const bundledDbReadStream = fs.createReadStream(bundledDb);
try {
await client.request(`POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name`, {
owner: repositoryNwo.owner,
repo: repositoryNwo.repo,
language,
name: `${language}-database`,
data: bundledDbReadStream,
headers: {
authorization: `token ${apiDetails.auth}`,
"Content-Type": "application/zip",
"Content-Length": bundledDbSize,
},
});
logger.debug(`Successfully uploaded database for ${language}`);
}
finally {
bundledDbReadStream.close();
}
}
catch (e) {
console.log(e);