UNPKG

517 BJavaScriptView Raw
1const fs = require('fs')
2const path = require('path')
3const zlib = require('zlib')
4
5module.exports = file => new Promise((resolve, reject) => {
6 let gzFile = `${file}.gz`
7
8 const filePath = path.resolve(file)
9 const gzFilePath = path.resolve(gzFile)
10
11 let gzip = zlib.createGzip()
12
13 const inputStream = fs.createReadStream(filePath)
14 const outStream = fs.createWriteStream(gzFilePath)
15
16 inputStream.pipe(gzip).pipe(outStream)
17
18 outStream.on('finish', () => {
19 fs.unlinkSync(filePath)
20 resolve()
21 })
22})