The pure Javascript BOSS serializer

The usage sample:

const Boss = require('boss.js');

function testBoss() {
    let src = { hello: 'world', data: [1,2,3]};
    let packed = Boss.dump(src);
    assert(JSON.stringify(Boss.load(packed)) == JSON.stringify(src));
    let reader = new Boss.Reader(packed);
    console.log(JSON.stringify(reader.read()));
    let writer = new Boss.Writer();
    writer.write(src);
    assert(packed.toString() == writer.get().toString() );
}

Note that usage model is slightly better than one in web UI library. We should migrate it to this interface mode too.

Pack any object to binary

let packed = Boss.dump(anyData);

returns Uint8Array with packed binary representation of anyData which must not be undefined.

Unpack any object from binary

let packed = Boss.dump(binaryData);
  • binaryDara: oacked BOSS data in Uint8Array typed array.

returns restored data object (e.g. objectm, array or whatever else BOSS does support).

Reader

let reader = new Boss.Reader(packed);
console.log(JSON.stringify(reader.read()));

Create

let reader = new Boss.Reader(packed);
  • packed should contain BOSS packed data in Uint8Array.

returns Boss.Reader instance.

Read stored object

let unpacked = reader.read();

returns unpacked object or undefined on end of stream reached.

Writer

let writer = new Boss.Writer();
writer.write(src);

Create

let writer = new Boss.Writer();

returns Boss.Writer instance ready to pack objects.

Write

writer.write(source);
  • source any javascript object to pack.

Get packed data

let packed = writer.get();

returns binary packed data in Uint8Array.

Please do not call writes after it as the behaviod is undefined and will vary.