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

Sometimes it thinks buffer is not a buffer #23

Open
liesislukas opened this issue Nov 2, 2018 · 1 comment
Open

Sometimes it thinks buffer is not a buffer #23

liesislukas opened this issue Nov 2, 2018 · 1 comment

Comments

@liesislukas
Copy link

liesislukas commented Nov 2, 2018

Haven't worked how exactly this happens but here is the code:

const brotli = require('brotli');

  try {
    result = brotli.compress(data, {
      mode: 1, // 0 = generic, 1 = text, 2 = font (WOFF2)
      quality, // 0 - 11
      lgwin: 22, // window size
    });
    result = Buffer.from(result);
  } catch (e) {
    console.error('error: ', e);
    console.log('data: ', data);
    console.log('typeof data: ', typeof data);
    console.log('isBuffer?: ', Buffer.isBuffer(data));
    result = data;
  }

I get error: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type object Error

so I added some more logging to double check what's coming to this compress function. The output:

data:  <Buffer 7b 22 6d 22 3a 22 50 4c 41 4e 5f 43 48 41 4e 47 45 22 2c 22 64 22 3a 7b 22 70 6c 61 6e 4e 65 77 22 3a 22 73 74 61 72 74 22 2c 22 70 6c 61 6e 4f 6c 64 ... >
typeof data:  object
isBuffer?:  true

After the failure, I continue using the result, which becomes uncompressed Buffer and just saves it to the database as binary data. Buffer seems to be perfectly fine. While I also can get it from the database, convert to string, parse JSON out of it and use as intended.

Nodejs version v10.8.0
npm brotli: 1.3.2

This is how i build this data variable:

    let data = {
        m: message || '',
        d: details || '',
        t: moment().unix(),  // when created timestamp
      };

      data = JSON.stringify(data);
      data = Buffer.from(data, 'utf8');
@liesislukas
Copy link
Author

any hope to dive into this?

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

1 participant