node_erlastic icon indicating copy to clipboard operation
node_erlastic copied to clipboard

compressed binary support

Open Cidan opened this issue 10 years ago • 5 comments

Hey,

I have a patch for bert.js that adds compressed binary support, however it requires node.js 0.12 at minimum, due to a bug in the zlib implementation in prior versions.

Is that acceptable, and if so, should I submit a PR?

Thanks!

Cidan avatar Jun 21 '15 20:06 Cidan

Hello, Yes it is OK to require node.js 0.12, my projects actually use io.js on earlier versions, maybe you can also add the requirement to the package.json.

Thank you very much for the proposal, I actually wanted to add this support.

awetzel avatar Jun 22 '15 14:06 awetzel

:+1:

benoitc avatar Nov 18 '15 15:11 benoitc

:+1:

matehat avatar Nov 18 '15 17:11 matehat

@Cidan : is this done .. having trouble to decode Compressed Term Format: Screenshot 2022-07-20 at 11 43 28 AM

harshagarwal00 avatar Jul 20 '22 06:07 harshagarwal00

Fix was very non-intuitive

const { unzip } = require('node:zlib');
const { promisify } = require('node:util');
const do_unzip = promisify(unzip);

//remove the first 6 bytes and inflate using zlib
const inflated = await do_unzip(buffer.subarray(6));
//we are skipping check for 131 in decode function rest of logic in decode function is the same
var Obj = Bert.decode_inner(inflated);
  if (Obj.rest.length !== 0) {
            throw ("Invalid BERT.");
  }
 return Obj.value;

harshagarwal00 avatar Jul 21 '22 11:07 harshagarwal00