Created
July 31, 2022 11:52
-
-
Save semlinker/656f15672b40adbd092c776b5b620726 to your computer and use it in GitHub Desktop.
HTTP Transfer Large Files
This file contains 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"); | |
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