Skip to content

Instantly share code, notes, and snippets.

@spemer
Created April 11, 2020 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spemer/50839a077109860a08b9173fbf621cb6 to your computer and use it in GitHub Desktop.
Save spemer/50839a077109860a08b9173fbf621cb6 to your computer and use it in GitHub Desktop.
compress.js
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