mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +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.
|
* @param {string[]} urls The URLs to the files to be downloaded.
|
||||||
*/
|
*/
|
||||||
export const downloadFiles = async (filePath, urls) => {
|
export const downloadFiles = async (filePath, urls) => {
|
||||||
const writeStream = createWriteStream(filePath, { flags: "a" });
|
|
||||||
const responses = await Promise.all(urls.map((url) => fetch(url)));
|
const responses = await Promise.all(urls.map((url) => fetch(url)));
|
||||||
|
|
||||||
for (const response of responses) {
|
for (const response of responses) {
|
||||||
const readable = ReadStream.from(response.body, {
|
const writeStream = createWriteStream(filePath, { flags: "a" });
|
||||||
autoDestroy: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
readable.on("end", () => {
|
ReadStream.from(response.body)
|
||||||
|
.on("end", () => {
|
||||||
writeStream.write("\n");
|
writeStream.write("\n");
|
||||||
});
|
})
|
||||||
|
.pipe(writeStream);
|
||||||
readable.pipe(writeStream, { end: false });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user