Skip to content

Instantly share code, notes, and snippets.

@semlinker
Created July 31, 2022 11:52
Show Gist options
  • Save semlinker/656f15672b40adbd092c776b5b620726 to your computer and use it in GitHub Desktop.
Save semlinker/656f15672b40adbd092c776b5b620726 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");
const util = require("util");
const readFile = util.promisify(fs.readFile);
const gzip = util.promisify(zlib.gzip);
const server = http.createServer(async (req, res) => {
res.writeHead(200, {
"Content-Type": "text/plain;charset=utf-8",
"Content-Encoding": "gzip"
});
const buffer = await readFile(__dirname + "/big-file.txt");
const gzipData = await gzip(buffer);
res.write(gzipData);
res.end();
});
server.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