-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdecompress.js
25 lines (19 loc) · 864 Bytes
/
decompress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict'
const { extname } = require('path')
const { createGunzip, createDeflate, createBrotliDecompress } = require('zlib')
const { PassThrough } = require('readable-stream')
const decompress = (key) => {
const extension = extname(key.toString())
if (['.gz', '.gzip'].includes(extension)) {
return createGunzip() // if the file is gzip return a transform stream to decompress it
}
if (['.zz', '.deflate'].includes(extension)) {
return createDeflate() // if the file is deflate return a transform stream to decompress it
}
if (createBrotliDecompress && ['.br', '.brotli'].includes(extension)) {
return createBrotliDecompress() // if the file is brotli return a transform stream to decompress it
}
// otherwise returns a passthrough stream (do not modify the content)
return new PassThrough()
}
module.exports = decompress