koajs/compress

Error in threshold checking?

felixsanz opened this issue · 3 comments

The option:

threshold

Minimum response size in bytes to compress. Default 1024 bytes or 1kb.

Can't be set to 0 (compress always) because the code var threshold = !options.threshold ? 1024 : .... When 0, the checking fails. It should be var threshold = options.threshold === undefined ? 1024 : ... (or even != null).

Would you accept a PR for this or do you think the minimum threshold should be 1 since there is no point in compressing a 0 byte response? (But not being able to use 0 to indicate "always" is kinda counter-intuitive).

sounds like a bug to me! maybe support false?

threshold: false doesn't make much sense to me, it's confusing the intention.

I think threshold: 0 is just fine since you want to compress from that size.

The thing is that compressing 0 bytes doesn't make sense. But threshold: 1 is weird as an option.

sorry for the late update. looks like the code is updated so that this is no longer relevant.

if (threshold && ctx.response.length < threshold) return