Created
November 5, 2021 09:55
-
-
Save zakcodez/af07a68823dfc99f77d2f11ce6cce26a to your computer and use it in GitHub Desktop.
Gzip a file using the zlib module
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
import zlib from "zlib"; | |
import fs from "fs"; | |
import stream from "stream"; | |
import { promisify } from "util"; | |
import readline from "readline"; | |
const pipe = promisify(stream.pipeline); | |
const { stdin, stdout, stderr } = process; | |
(async function () { | |
const rl = readline.createInterface({ input: stdin, output: stdout }); | |
const filename = await new Promise<string>((resolve, reject) => | |
rl.question("What file would you like to compress? ", (file) => resolve(file))); | |
const input = fs.createReadStream(filename); | |
const output = fs.createWriteStream(`${filename}.gz`); | |
const gzip = zlib.createGzip(); | |
await pipe(input, gzip, output); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment