Created
April 11, 2020 16:46
-
-
Save spemer/50839a077109860a08b9173fbf621cb6 to your computer and use it in GitHub Desktop.
Revisions
-
spemer created this gist
Apr 11, 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 @@ const fs = require("fs"); const zlib = require("zlib"); var dirs = ["../public/sitemap"]; dirs.forEach((dir) => { fs.readdirSync(dir).forEach((file) => { if (file.endsWith(".xml")) { // gzip const fileContents = fs.createReadStream(dir + "/" + file); const writeStream = fs.createWriteStream(dir + "/" + file + ".gz"); const zip = zlib.createGzip(); fileContents .pipe(zip) .on("error", (err) => console.error(err)) .pipe(writeStream) .on("error", (err) => console.error(err)); } }); });