Skip to content

Commit fc4146a

Browse files
committed
Update compress.ts
1 parent c799b18 commit fc4146a

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/compress.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ export type compressor = ((buf: zlib.InputType) => Buffer)
2323
export type compressFormat = keyof typeof compressors
2424

2525
function switchCompressor(format: compressFormat): compressor {
26-
if (!Object.prototype.hasOwnProperty.call(compressors, format)) {
26+
if (Object.prototype.hasOwnProperty.call(compressors, format)) {
27+
const f = compressors[format]
28+
if (f) return f
29+
throw Error(`Could not get compressor: Please upgrade node.js or set your compressor function.`)
30+
}
31+
let funcName = format + 'CompressSync'
32+
if (Object.prototype.hasOwnProperty.call(zlib, funcName)) {
2733
const f = zlib[format + 'CompressSync']
28-
if (!f) throw Error(`Could not get compressor: Unknown compress format '${format}', please set your compressor function.`)
29-
return f
34+
if (typeof f == 'function') return f
3035
}
31-
const f = compressors[format]
32-
if (!f) throw Error(`Could not get compressor: Please upgrade node.js or set your compressor function.`)
33-
return f
36+
throw Error(`Could not get compressor: Unknown compress format '${format}', please set your compressor function.`)
3437
}
3538

3639
export function compress(format: compressFormat, buf: zlib.InputType, useBase128: boolean, compressor: compressor) {

0 commit comments

Comments
 (0)