mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 05:31:50 +00:00
refactored downloadFiles to a more efficient approach
This commit is contained in:
+5
-8
@@ -49,19 +49,16 @@ export const isComment = (value) =>
|
||||
* @param {string[]} urls The URLs to the files to be downloaded.
|
||||
*/
|
||||
export const downloadFiles = async (filePath, urls) => {
|
||||
const writeStream = createWriteStream(filePath, { flags: "a" });
|
||||
const responses = await Promise.all(urls.map((url) => fetch(url)));
|
||||
|
||||
for (const response of responses) {
|
||||
const readable = ReadStream.from(response.body, {
|
||||
autoDestroy: true,
|
||||
});
|
||||
const writeStream = createWriteStream(filePath, { flags: "a" });
|
||||
|
||||
readable.on("end", () => {
|
||||
ReadStream.from(response.body)
|
||||
.on("end", () => {
|
||||
writeStream.write("\n");
|
||||
});
|
||||
|
||||
readable.pipe(writeStream, { end: false });
|
||||
})
|
||||
.pipe(writeStream);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user