11

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.

Mike Vella
  • 10,187
  • 14
  • 59
  • 86
Tarelli
  • 634
  • 7
  • 18

1 Answers1

7

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

Javier Neyra
  • 1,239
  • 11
  • 12
  • That is quite possibly the best answer in the history of the universe. – jkh Jan 18 '15 at 19:33
  • 1
    Emscripten is great and decently fast. The cost is in the malloc, memcpy (there & back), free. Remember, it's a heap simulator. – user1212212 Mar 16 '15 at 23:52
  • emscripten is great but only if you are fluent in C/C++ since you'll have to make A LOT of post-compile modifications to make the code reasonably usable/readable.. *not for the faint-hearted* –  May 04 '15 at 20:32