Skip to content

Instantly share code, notes, and snippets.

@semlinker
Created July 31, 2022 15:10
Show Gist options
  • Save semlinker/58b55659787a4e91d7fe00f67bd195c6 to your computer and use it in GitHub Desktop.
Save semlinker/58b55659787a4e91d7fe00f67bd195c6 to your computer and use it in GitHub Desktop.
HTTP Transfer Large Files
const fs = require("fs");
const zlib = require("zlib");
const http = require("http");
http
.createServer((req, res) => {
res.writeHead(200, {
"Content-Type": "text/plain;charset=utf-8",
"Content-Encoding": "gzip",
});
fs.createReadStream(__dirname + "/big-file.txt")
.setEncoding("utf-8")
.pipe(zlib.createGzip())
.pipe(res);
})
.listen(3000, () => {
console.log("app starting at port 3000");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment