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

Unable to decompress output of lz4c #7

Open
paddor opened this issue Mar 14, 2020 · 1 comment
Open

Unable to decompress output of lz4c #7

paddor opened this issue Mar 14, 2020 · 1 comment

Comments

@paddor
Copy link

paddor commented Mar 14, 2020

It seems lz4js is unable to decompress the output of lz4c. I have simply Base64-encoded the output of echo 'hello world' | lz4c, put it in a JSON message, sent it over a websocket to the browser, had the browser do this:

  onMessage(event) {
    const encoder = new TextEncoder();
    const decoder = new TextDecoder();

    try  {
      let payload_b64 = event.data;
      console.info("b64 payload", payload_b64);
      let payload_bin = atob(payload_b64);
      console.info("bin payload", payload_bin);
      let payload_uint8 = encoder.encode(payload_bin);
      console.info("compressed bin payload (Array)", payload_uint8);
      let payload = lz4js.decompress(payload_uint8);
      console.info("decompressed payload (Uint8Array)", payload);
      payload = decoder.decode(payload);
      console.info("payload (JSON)", payload);
      payload = JSON.parse(payload);
      console.info("payload", payload);

    } catch (e) {
      if (e instanceof SyntaxError) {
        console.error("received invalid message", event.data);
        return;
      } else {
        console.error("error", e);
      }
    }

Btw, maybe this is related to the same issue, but this does not work as intended:

console.log('LZ4 round trip', lz4js.decompress(lz4js.compress("bla bla bla")));
@kylebarron
Copy link

but this does not work as intended

The lz4js API works on arrays. You can't pass a string to it. This works:

> lz4js.decompress(lz4js.compress(new Uint8Array([1, 2, 3, 4])))
Uint8Array(4) [ 1, 2, 3, 4 ]

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

2 participants