Created
April 11, 2020 16:46
-
-
Save spemer/50839a077109860a08b9173fbf621cb6 to your computer and use it in GitHub Desktop.
compress.js
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 characters
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)); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment