oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.62k stars 2.72k forks source link

GZIP negative windowBits argument not working #6280

Open robobun opened 1 year ago

robobun commented 1 year ago

Setting the windowBits argument in range of -9..-15 causes the function to return an "invalid buffer", opposed to using a positive number which outputs a buffer properly. Using:

Bun.gzipSync(serialize({'test':2,'test3':[4,6,7,8],'test2':-1}), {
    level: 9, memLevel:9, windowBits: -15
})
2 | import {readFileSync, writeFileSync} from 'fs';
3 | import {deserialize, serialize} from 'bson';
4 | import {inspect} from 'util';
5 |
6 | console.log(1);
7 | console.log(Bun.gzipSync(serialize({'test':2,'test3':[4,6,7,8],'test2':-1}), {
               ^
TypeError: Invalid buffer
 code: "ERR_INVALID_ARG_TYPE"

      at /mnt/c/.../testing.js:7:12

Originally reported on Discord: GZIP negative windowBits argument not working

nektro commented 1 month ago

Setting the windowBits argument in range of -9..-15 to the underlying zlib library is used to signal that the incoming chunks will be in deflate/inflate's raw mode. so there being an error here is correct but this message is ergo very misleading. thank you for the report, i'll be fixing this soon.