bsonize
BSON serialization and deserialization.
Installation
npm i bsonize -S
API documentation
serialize(obj)
deserialize(buffer, [isArray=false])
serializeToFile(file, obj, [cb])
deserializeFromFile(file, [isArray=false], [cb])
serialize(obj)
- obj (
Object|Array
) The object/array to serialize. - returns {Buffer} Result in BSON.
Serializes an object/array to BSON.
bsonize;//=> <Buffer 28 00 00 00 10 ..>
deserialize(buffer, [isArray=false])
- buffer (
Buffer
) The buffer contains BSON data. - [isArray=false] (
Boolean
) Whether result is an array or not. - returns {Object|Array} The object/array after deserialize.
Deserializes an object/array from BSON.
var buffer = 'IQAAABAwAJQmAAAQMQAFAAAAEDIAKwAAABAzABUAAAAA' 'base64'; bsonize;//=> { 0: 9876, 1: 5, 2: 43, 3: 21 } bsonize;//=> [ 9876, 5, 43, 21 ]
serializeToFile(file, obj, [cb])
- file (
String
) File path. - obj (
Object|Array
) The array/object to serialize. - [cb] (
Function
) Callback function. The buffer contains BSON data after serialize will be passed to. - returns {Promise} A promise will be returned if callback function is not set.
Serializes an object/array to BSON and write to file.
bsonize;
deserializeFromFile(file, [isArray=false], [cb])
- file (
String
) File path. - [isArray=false] (
Boolean
) Whether result is an array or not. - [cb] (
Function
) Callback function. The deserialized object/array will be passed to. - returns {Promise} A promise will be returned if callback function is not set.
Deserializes an object/array from BSON file.
bsonize; bsonize;
License
MIT licensed.