Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ReadHuffmanCode] invalid num_codes or space in decompress method #31

Open
rajatraj733 opened this issue Apr 18, 2020 · 5 comments
Open

Comments

@rajatraj733
Copy link

rajatraj733 commented Apr 18, 2020

I'm using brotli with react version 16.13. By just import brotli in react component file shows this error.
This is the error stack:

Uncaught TypeError: Cannot read property 'slice' of null
    at encode.js:11
    at Object.<anonymous> (encode.js:11)
    at Object../node_modules/brotli/build/encode.js (encode.js:56)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/brotli/compress.js (compress.js:1)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/brotli/index.js (index.js:1)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/actions/appActions.js (role-resource-constants.js:91)

Brotli version - 1.3.2

@rajatraj733
Copy link
Author

As I wanted to use just decompress method hence, I avoided this issue by:

import decompress from 'brotli/decompress'

Now, I got into another issue:

index.js:1 Error: [ReadHuffmanCode] invalid num_codes or space
    at ReadHuffmanCode (decode.js:323)
    at HuffmanTreeGroup.push../node_modules/brotli/dec/decode.js.HuffmanTreeGroup.decode (decode.js:392)
    at BrotliDecompress (decode.js:747)
    at BrotliDecompressBuffer (decode.js:583)
    at _callee$ (appActions.js:104)

I'm pretty sure there is no space in the compressed string.

@rajatraj733 rajatraj733 changed the title Cannot read property 'slice' of null [ReadHuffmanCode] invalid num_codes or space in decompress method Apr 19, 2020
@crimson-med
Copy link

Had the same issue so ended up using the nodejs builtin zlib library

@auburnsummer
Copy link

For me, I found that I got this error when I inadvertently passed an ArrayBuffer to decompress instead of a Buffer.

I used Buffer.from (https://www.npmjs.com/package/buffer) to create a Buffer from the ArrayBuffer first, then the decompress function worked.

@darvesh
Copy link

darvesh commented May 20, 2021

compress

const foo = compress(Buffer.from(str));

decompress

const arrayBuff = decompress(Buffer.from(foo));
const str = Buffer.from(arrayBuff).toString("utf-8");

@Amnesthesia
Copy link

I ran into this as well and the solution was to pass Buffer.from(compressed, 'binary') the second argument 'binary'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants