chore: tests

This commit is contained in:
zhom
2026-04-25 17:55:31 +04:00
parent 01b1bbedda
commit 446bdb1f46
+19 -1
View File
@@ -48,6 +48,7 @@ async function downloadFile(url, dest) {
protocol
.get(url, (response) => {
if (response.statusCode === 302 || response.statusCode === 301) {
file.close();
downloadFile(response.headers.location, dest)
.then(resolve)
.catch(reject);
@@ -55,11 +56,28 @@ async function downloadFile(url, dest) {
}
if (response.statusCode !== 200) {
file.close();
reject(new Error(`Failed to download: ${response.statusCode}`));
return;
}
pipeline(response, file).then(resolve).catch(reject);
// pipeline() resolves once the source ends but doesn't await the
// destination fd closing. Linux refuses to exec a file whose write
// fd is still open (ETXTBSY), so explicitly wait for 'close'.
pipeline(response, file)
.then(
() =>
new Promise((res, rej) => {
if (file.closed) {
res();
} else {
file.once("close", res);
file.once("error", rej);
}
}),
)
.then(resolve)
.catch(reject);
})
.on("error", reject);
});