Using lz4 compression in javascript without Node.js

5.9k views Asked by At

I am trying to get LZ4 decompression to work client-side in pure JavaScript.

I found this JavaScript library but it's meant to be used with Node.js. Within the same repository I found a library which can in theory be used in the browser. The problem is that such library expects still Node.js buffers which again I don't have since I'm not using Node.js and all of this is happening client side (I logged a bug here to try and get a hold of some pointers for how to use it).

I then looked for a porting of Node.js buffers and I found this repository. The problem is that when I use it I get this error in both Chrome and Firefox:

TypeError: this is not a typed array

I logged this bug report for this. I feel like combining those two libraries I am not too far from achieving lz4 decompression in pure JavaScript but having never worked before with ArrayBuffer, Uint8Array and Node.js I am struggling to connect the dots.

My question: Has anyone successfully managed to decompress LZ4 in pure JavaScript? Any advice or pointers? Thanks in advance.

1

There are 1 answers

3
Javier Neyra On

I will provide an IDEA not a solution, you can try this repository

https://code.google.com/p/lz4/

it has a pure c implementation of LZ4

you can compile that with clang to llvm bitcode

and when you have that, you use this https://github.com/kripken/emscripten

to get javascript out of the llvm bitcode

its like c to javascript compilation, it maybe sound crazy but if you look at what they already achieved... i dont know it could actually work.

take a look here they ported lots of things to javascript with this tool for example this one: https://github.com/kripken/lzma.js