var data = new Buffer('This is a string');
var compressed;
var decompressed;
var brotli = require("brotli");
compressed = brotli.compress(data);
decompressed = brotli.decompress(compressed);
console.log('brotli:');
console.log(JSON.stringify(decompressed));
console.log(decompressed.toString());
var iltorb = require('iltorb');
compressed = iltorb.compressSync(data);
decompressed = iltorb.decompressSync(compressed);
console.log('iltorb:');
console.log(JSON.stringify(decompressed));
console.log(decompressed.toString());
Then I run this code the I get output:
brotli:
{"0":84,"1":104,"2":105,"3":115,"4":32,"5":105,"6":115,"7":32,"8":97,"9":32,"10":115,"11":116,"12":114,"13":105,"14":110,"15":103}
84,104,105,115,32,105,115,32,97,32,115,116,114,105,110,103
iltorb:
{"type":"Buffer","data":[84,104,105,115,32,105,115,32,97,32,115,116,114,105,110,103]}
This is a string
If I change code to:
var brotli = require("brotli");
compressed = brotli.compress(data);
decompressed = brotli.decompress(compressed);
decompressed = new Buffer(decompressed);
console.log('brotli:');
console.log(JSON.stringify(decompressed));
console.log(decompressed.toString());
>brotli:
>{"type":"Buffer","data":[84,104,105,115,32,105,115,32,97,32,115,116,114,105,110,103]}
>This is a string
Yes, brotli returns Uint8Array instead of Buffer because the browser buffer library is quite large. If you want a Buffer, you can wrap it yourself as in your second example.
I have a code snippet:
Then I run this code the I get output:
If I change code to:
then all works right