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")));
It seems lz4js is unable to decompress the output of
lz4c
. I have simply Base64-encoded the output ofecho 'hello world' | lz4c
, put it in a JSON message, sent it over a websocket to the browser, had the browser do this:Btw, maybe this is related to the same issue, but this does not work as intended: