Created
March 2, 2020 12:48
Revisions
-
thekarel created this gist
Mar 2, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ async function fetchOnceAndSaveToDiskWithBuffer(url, filename) { return new Promise(resolve => { if (fs.existsSync(filename)) { resolve(readFile(filename)); return; } const file = fs.createWriteStream(filename); console.log(` * Downloading from: ${url}`); https.get(url, (response) => { const unzip = zlib.createGunzip(); response.pipe(unzip).pipe(file); unzip.on('end', () => { resolve(readFile(filename)); }); }); }); }