Using libavutil's LZO algorithm in Node.js: Part 2
Yesterday I started wrapping the LZO algorithm inside libavutil into a Node.js library. I'm still working on the C code, but let's have a look at how to test if it's actually working. I needed to generate some LZO-compressed date, so I installed the lzop
tool using sudo apt install lzop
. Then I generated a compressed file using:
echo "The quick quick quick brown fox" | lzop > y.lzo
I opened the resulting file in a hex editor and found the compressed bit, which looked like this: The quick q)�brown fox
. Based on this, I figured that if I skip the first 50 bytes of the file, I get to the actual compressed data. So I wrote the following JS code to test if the decompression algorithm works:
const binding = require('node-gyp-build')(__dirname);
const fs = require('fs');
fs.readFile('y.lzo', (err, data) => {
if (err) throw err;
const skip = 50;
const ret = binding.decompress(data.slice(skip), data.length - skip);
console.log(ret.toString());
});
module.exports = binding;
So far I can see that the data decompresses successfully, but I'm still having a bit of trouble passing back the data into a Node.js Buffer object.
#Node.js