Comparing version 0.1.13 to 1.0.0
@@ -13,2 +13,3 @@ var bson = null; | ||
} catch(err) { | ||
console.log(err) | ||
// Attempt to load the release bson version | ||
@@ -15,0 +16,0 @@ try { |
36
index.js
@@ -1,2 +0,16 @@ | ||
var BSON = require('./ext').BSON; | ||
var BSON = require('./ext').BSON, | ||
Binary = require('./lib/bson/binary'), | ||
Code = require('./lib/bson/code'), | ||
DBRef = require('./lib/bson/db_ref'), | ||
Decimal128 = require('./lib/bson/decimal128'), | ||
Double = require('./lib/bson/double'), | ||
Int32 = require('./lib/bson/int_32'), | ||
Long = require('./lib/bson/long'), | ||
Map = require('./lib/bson/map'), | ||
MaxKey = require('./lib/bson/max_key'), | ||
MinKey = require('./lib/bson/min_key'), | ||
ObjectId = require('./lib/bson/objectid'), | ||
BSONRegExp = require('./lib/bson/regexp'), | ||
Symbol = require('./lib/bson/symbol'), | ||
Timestamp = require('./lib/bson/timestamp'); | ||
@@ -14,2 +28,20 @@ // BSON MAX VALUES | ||
module.exports = BSON; | ||
// Add BSON types to function creation | ||
BSON.Binary = Binary; | ||
BSON.Code = Code; | ||
BSON.DBRef = DBRef; | ||
BSON.Decimal128 = Decimal128; | ||
BSON.Double = Double; | ||
BSON.Int32 = Int32; | ||
BSON.Long = Long; | ||
BSON.Map = Map; | ||
BSON.MaxKey = MaxKey; | ||
BSON.MinKey = MinKey; | ||
BSON.ObjectId = ObjectId; | ||
BSON.ObjectID = ObjectId; | ||
BSON.BSONRegExp = BSONRegExp; | ||
BSON.Symbol = Symbol; | ||
BSON.Timestamp = Timestamp; | ||
// Return the BSON | ||
module.exports = BSON; |
@@ -5,3 +5,6 @@ /** | ||
*/ | ||
if(typeof window === 'undefined') { | ||
// Test if we're in Node via presence of "global" not absence of "window" | ||
// to support hybrid environments like Electron | ||
if(typeof global !== 'undefined') { | ||
var Buffer = require('buffer').Buffer; // TODO just use global Buffer | ||
@@ -12,3 +15,3 @@ } | ||
* A class representation of the BSON Binary type. | ||
* | ||
* | ||
* Sub types | ||
@@ -29,3 +32,3 @@ * - **BSON.BSON_BINARY_SUBTYPE_DEFAULT**, default BSON type. | ||
if(!(this instanceof Binary)) return new Binary(buffer, subType); | ||
this._bsontype = 'Binary'; | ||
@@ -36,3 +39,3 @@ | ||
this.position = 0; | ||
} else { | ||
} else { | ||
this.sub_type = subType == null ? BSON_BINARY_SUBTYPE_DEFAULT : subType; | ||
@@ -54,3 +57,3 @@ this.position = 0; | ||
} else { | ||
this.buffer = buffer; | ||
this.buffer = buffer; | ||
} | ||
@@ -60,3 +63,3 @@ this.position = buffer.length; | ||
if(typeof Buffer != 'undefined') { | ||
this.buffer = new Buffer(Binary.BUFFER_SIZE); | ||
this.buffer = new Buffer(Binary.BUFFER_SIZE); | ||
} else if(typeof Uint8Array != 'undefined'){ | ||
@@ -82,7 +85,7 @@ this.buffer = new Uint8Array(new ArrayBuffer(Binary.BUFFER_SIZE)); | ||
if(typeof byte_value != 'number' && byte_value < 0 || byte_value > 255) throw new Error("only accepts number in a valid unsigned byte range 0-255"); | ||
// Decode the byte value once | ||
var decoded_byte = null; | ||
if(typeof byte_value == 'string') { | ||
decoded_byte = byte_value.charCodeAt(0); | ||
decoded_byte = byte_value.charCodeAt(0); | ||
} else if(byte_value['length'] != null) { | ||
@@ -93,7 +96,7 @@ decoded_byte = byte_value[0]; | ||
} | ||
if(this.buffer.length > this.position) { | ||
this.buffer[this.position++] = decoded_byte; | ||
} else { | ||
if(typeof Buffer != 'undefined' && Buffer.isBuffer(this.buffer)) { | ||
if(typeof Buffer != 'undefined' && Buffer.isBuffer(this.buffer)) { | ||
// Create additional overflow buffer | ||
@@ -112,4 +115,4 @@ var buffer = new Buffer(Binary.BUFFER_SIZE + this.buffer.length); | ||
buffer = new Array(Binary.BUFFER_SIZE + this.buffer.length); | ||
} | ||
} | ||
// We need to copy all the content to the new array | ||
@@ -119,3 +122,3 @@ for(var i = 0; i < this.buffer.length; i++) { | ||
} | ||
// Reassign the buffer | ||
@@ -144,5 +147,5 @@ this.buffer = buffer; | ||
// If we are in node.js | ||
if(typeof Buffer != 'undefined' && Buffer.isBuffer(this.buffer)) { | ||
if(typeof Buffer != 'undefined' && Buffer.isBuffer(this.buffer)) { | ||
buffer = new Buffer(this.buffer.length + string.length); | ||
this.buffer.copy(buffer, 0, 0, this.buffer.length); | ||
this.buffer.copy(buffer, 0, 0, this.buffer.length); | ||
} else if(Object.prototype.toString.call(this.buffer) == '[object Uint8Array]') { | ||
@@ -156,3 +159,3 @@ // Create a new buffer | ||
} | ||
// Assign the new buffer | ||
@@ -167,10 +170,10 @@ this.buffer = buffer; | ||
} else if(typeof Buffer != 'undefined' && typeof string == 'string' && Buffer.isBuffer(this.buffer)) { | ||
this.buffer.write(string, 'binary', offset); | ||
this.buffer.write(string, offset, 'binary'); | ||
this.position = (offset + string.length) > this.position ? (offset + string.length) : this.position; | ||
// offset = string.length; | ||
} else if(Object.prototype.toString.call(string) == '[object Uint8Array]' | ||
|| Object.prototype.toString.call(string) == '[object Array]' && typeof string != 'string') { | ||
} else if(Object.prototype.toString.call(string) == '[object Uint8Array]' | ||
|| Object.prototype.toString.call(string) == '[object Array]' && typeof string != 'string') { | ||
for(var i = 0; i < string.length; i++) { | ||
this.buffer[offset++] = string[i]; | ||
} | ||
} | ||
@@ -199,3 +202,3 @@ this.position = offset > this.position ? offset : this.position; | ||
: this.position; | ||
// Let's return the data based on the type we have | ||
@@ -222,3 +225,3 @@ if(this.buffer['slice']) { | ||
Binary.prototype.value = function value(asRaw) { | ||
asRaw = asRaw == null ? false : asRaw; | ||
asRaw = asRaw == null ? false : asRaw; | ||
@@ -228,3 +231,3 @@ // Optimize to serialize for the situation where the data == size of buffer | ||
return this.buffer; | ||
// If it's a node.js buffer object | ||
@@ -280,3 +283,3 @@ if(typeof Buffer != 'undefined' && Buffer.isBuffer(this.buffer)) { | ||
* Binary default subtype | ||
* @ignore | ||
* @ignore | ||
*/ | ||
@@ -294,3 +297,3 @@ var BSON_BINARY_SUBTYPE_DEFAULT = 0; | ||
buffer[i] = data.charCodeAt(i); | ||
} | ||
} | ||
// Write the string to the buffer | ||
@@ -310,3 +313,3 @@ return buffer; | ||
} | ||
return result; | ||
return result; | ||
}; | ||
@@ -318,3 +321,3 @@ | ||
* Default BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -325,3 +328,3 @@ **/ | ||
* Function BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -332,3 +335,3 @@ **/ | ||
* Byte Array BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -339,3 +342,3 @@ **/ | ||
* OLD UUID BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -346,3 +349,3 @@ **/ | ||
* UUID BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -353,3 +356,3 @@ **/ | ||
* MD5 BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -360,3 +363,3 @@ **/ | ||
* User BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -370,2 +373,2 @@ **/ | ||
module.exports = Binary; | ||
module.exports.Binary = Binary; | ||
module.exports.Binary = Binary; |
@@ -13,3 +13,3 @@ /** | ||
this.code = code; | ||
this.scope = scope == null ? {} : scope; | ||
this.scope = scope; | ||
}; | ||
@@ -25,2 +25,2 @@ | ||
module.exports = Code; | ||
module.exports.Code = Code; | ||
module.exports.Code = Code; |
@@ -10,3 +10,3 @@ /** | ||
if(!(this instanceof Double)) return new Double(value); | ||
this._bsontype = 'Double'; | ||
@@ -34,2 +34,2 @@ this.value = value; | ||
module.exports = Double; | ||
module.exports.Double = Double; | ||
module.exports.Double = Double; |
/** | ||
* Module dependencies. | ||
* @ignore | ||
*/ | ||
var BinaryParser = require('./binary_parser').BinaryParser; | ||
/** | ||
* Machine id. | ||
@@ -29,6 +23,8 @@ * | ||
var ObjectID = function ObjectID(id) { | ||
// Duck-typing to support ObjectId from different npm packages | ||
if(id instanceof ObjectID) return id; | ||
if(!(this instanceof ObjectID)) return new ObjectID(id); | ||
if((id instanceof ObjectID)) return id; | ||
this._bsontype = 'ObjectID'; | ||
var __id = null; | ||
@@ -48,2 +44,7 @@ var valid = ObjectID.isValid(id); | ||
this.id = id; | ||
} else if(id != null && id.toHexString) { | ||
// Duck-typing to support ObjectId from different npm packages | ||
return id; | ||
} else { | ||
throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters"); | ||
} | ||
@@ -73,3 +74,12 @@ | ||
var hexString = ''; | ||
if(!this.id || !this.id.length) { | ||
throw new Error('invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is [' + JSON.stringify(this.id) + ']'); | ||
} | ||
if(this.id instanceof _Buffer) { | ||
hexString = convertToHex(this.id); | ||
if(ObjectID.cacheHexString) this.__id = hexString; | ||
return hexString; | ||
} | ||
for (var i = 0; i < this.id.length; i++) { | ||
@@ -106,20 +116,36 @@ hexString += hexTable[this.id.charCodeAt(i)]; | ||
/** | ||
* Generate a 12 byte id string used in ObjectID's | ||
* Generate a 12 byte id buffer used in ObjectID's | ||
* | ||
* @method | ||
* @param {number} [time] optional parameter allowing to pass in a second based timestamp. | ||
* @return {string} return the 12 byte id binary string. | ||
* @return {Buffer} return the 12 byte id buffer string. | ||
*/ | ||
ObjectID.prototype.generate = function(time) { | ||
if ('number' != typeof time) { | ||
time = parseInt(Date.now()/1000,10); | ||
time = ~~(Date.now()/1000); | ||
} | ||
var time4Bytes = BinaryParser.encodeInt(time, 32, true, true); | ||
/* for time-based ObjectID the bytes following the time will be zeroed */ | ||
var machine3Bytes = BinaryParser.encodeInt(MACHINE_ID, 24, false); | ||
var pid2Bytes = BinaryParser.fromShort(typeof process === 'undefined' ? Math.floor(Math.random() * 100000) : process.pid % 0xFFFF); | ||
var index3Bytes = BinaryParser.encodeInt(this.get_inc(), 24, false, true); | ||
return time4Bytes + machine3Bytes + pid2Bytes + index3Bytes; | ||
// Use pid | ||
var pid = (typeof process === 'undefined' ? Math.floor(Math.random() * 100000) : process.pid) % 0xFFFF; | ||
var inc = this.get_inc(); | ||
// Buffer used | ||
var buffer = new Buffer(12); | ||
// Encode time | ||
buffer[3] = time & 0xff; | ||
buffer[2] = (time >> 8) & 0xff; | ||
buffer[1] = (time >> 16) & 0xff; | ||
buffer[0] = (time >> 24) & 0xff; | ||
// Encode machine | ||
buffer[6] = MACHINE_ID & 0xff; | ||
buffer[5] = (MACHINE_ID >> 8) & 0xff; | ||
buffer[4] = (MACHINE_ID >> 16) & 0xff; | ||
// Encode pid | ||
buffer[8] = pid & 0xff; | ||
buffer[7] = (pid >> 8) & 0xff; | ||
// Encode index | ||
buffer[11] = inc & 0xff; | ||
buffer[10] = (inc >> 8) & 0xff; | ||
buffer[9] = (inc >> 16) & 0xff; | ||
// Return the buffer | ||
return buffer; | ||
}; | ||
@@ -162,9 +188,18 @@ | ||
*/ | ||
ObjectID.prototype.equals = function equals (otherID) { | ||
if(otherID == null) return false; | ||
var id = (otherID instanceof ObjectID || otherID.toHexString) | ||
? otherID.id | ||
: ObjectID.createFromHexString(otherID).id; | ||
ObjectID.prototype.equals = function equals (otherId) { | ||
var id; | ||
return this.id === id; | ||
if(otherId instanceof ObjectID) { | ||
return this.toString() == otherId.toString(); | ||
} else if(typeof otherId == 'string' && ObjectID.isValid(otherId) && otherId.length == 12 && this.id instanceof _Buffer) { | ||
return otherId === this.id.toString('binary'); | ||
} else if(typeof otherId == 'string' && ObjectID.isValid(otherId) && otherId.length == 24) { | ||
return otherId.toLowerCase() === this.toHexString(); | ||
} else if(typeof otherId == 'string' && ObjectID.isValid(otherId) && otherId.length == 12) { | ||
return otherId === this.id; | ||
} else if(otherId != null && (otherId instanceof ObjectID || otherId.toHexString)) { | ||
return otherId.toHexString() === this.toHexString(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
@@ -180,3 +215,4 @@ | ||
var timestamp = new Date(); | ||
timestamp.setTime(Math.floor(BinaryParser.decodeInt(this.id.substring(0,4), 32, true, true)) * 1000); | ||
var time = this.id[3] | this.id[2] << 8 | this.id[1] << 16 | this.id[0] << 24; | ||
timestamp.setTime(Math.floor(time) * 1000); | ||
return timestamp; | ||
@@ -188,3 +224,3 @@ } | ||
*/ | ||
ObjectID.index = parseInt(Math.random() * 0xFFFFFF, 10); | ||
ObjectID.index = ~~(Math.random() * 0xFFFFFF); | ||
@@ -206,7 +242,24 @@ /** | ||
ObjectID.createFromTime = function createFromTime (time) { | ||
var id = BinaryParser.encodeInt(time, 32, true, true) + | ||
BinaryParser.encodeInt(0, 64, true, true); | ||
return new ObjectID(id); | ||
var buffer = new Buffer([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); | ||
// Encode time into first 4 bytes | ||
buffer[3] = time & 0xff; | ||
buffer[2] = (time >> 8) & 0xff; | ||
buffer[1] = (time >> 16) & 0xff; | ||
buffer[0] = (time >> 24) & 0xff; | ||
// Return the new objectId | ||
return new ObjectID(buffer); | ||
}; | ||
// Lookup tables | ||
var encodeLookup = '0123456789abcdef'.split('') | ||
var decodeLookup = [] | ||
var i = 0 | ||
while (i < 10) decodeLookup[0x30 + i] = i++ | ||
while (i < 16) decodeLookup[0x41 - 10 + i] = decodeLookup[0x61 - 10 + i] = i++ | ||
var _Buffer = Buffer; | ||
var convertToHex = function(bytes) { | ||
return bytes.toString('hex'); | ||
} | ||
/** | ||
@@ -219,24 +272,24 @@ * Creates an ObjectID from a hex string representation of an ObjectID. | ||
*/ | ||
ObjectID.createFromHexString = function createFromHexString (hexString) { | ||
ObjectID.createFromHexString = function createFromHexString (string) { | ||
// Throw an error if it's not a valid setup | ||
if(typeof hexString === 'undefined' || hexString != null && hexString.length != 24) | ||
if(typeof string === 'undefined' || string != null && string.length != 24) | ||
throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters"); | ||
var len = hexString.length; | ||
var length = string.length; | ||
if(len > 12*2) { | ||
if(length > 12*2) { | ||
throw new Error('Id cannot be longer than 12 bytes'); | ||
} | ||
var result = '' | ||
, string | ||
, number; | ||
// Calculate lengths | ||
var sizeof = length >> 1; | ||
var array = new _Buffer(sizeof); | ||
var n = 0; | ||
var i = 0; | ||
for (var index = 0; index < len; index += 2) { | ||
string = hexString.substr(index, 2); | ||
number = parseInt(string, 16); | ||
result += BinaryParser.fromByte(number); | ||
while (i < length) { | ||
array[n++] = decodeLookup[string.charCodeAt(i++)] << 4 | decodeLookup[string.charCodeAt(i++)] | ||
} | ||
return new ObjectID(result, hexString); | ||
return new ObjectID(array); | ||
}; | ||
@@ -253,9 +306,24 @@ | ||
if(id != null && 'number' != typeof id && (id.length != 12 && id.length != 24)) { | ||
return false; | ||
} else { | ||
// Check specifically for hex correctness | ||
if(typeof id == 'string' && id.length == 24) return checkForHexRegExp.test(id); | ||
if(typeof id == 'number') { | ||
return true; | ||
} | ||
if(typeof id == 'string') { | ||
return id.length == 12 || (id.length == 24 && checkForHexRegExp.test(id)); | ||
} | ||
if(id instanceof ObjectID) { | ||
return true; | ||
} | ||
if(id instanceof _Buffer) { | ||
return true; | ||
} | ||
// Duck-Typing detection of ObjectId like objects | ||
if(id.toHexString) { | ||
return id.id.length == 12 || (id.id.length == 24 && checkForHexRegExp.test(id.id)); | ||
} | ||
return false; | ||
}; | ||
@@ -269,9 +337,10 @@ | ||
, get: function () { | ||
return Math.floor(BinaryParser.decodeInt(this.id.substring(0,4), 32, true, true)); | ||
return this.id[3] | this.id[2] << 8 | this.id[1] << 16 | this.id[0] << 24; | ||
} | ||
, set: function (value) { | ||
var value = BinaryParser.encodeInt(value, 32, true, true); | ||
this.id = value + this.id.substr(4); | ||
// delete this.__id; | ||
this.toHexString(); | ||
// Encode time into first 4 bytes | ||
this.id[3] = value & 0xff; | ||
this.id[2] = (value >> 8) & 0xff; | ||
this.id[1] = (value >> 16) & 0xff; | ||
this.id[0] = (value >> 24) & 0xff; | ||
} | ||
@@ -285,2 +354,2 @@ }); | ||
module.exports.ObjectID = ObjectID; | ||
module.exports.ObjectId = ObjectID; | ||
module.exports.ObjectId = ObjectID; |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.1.13", | ||
"version": "1.0.0", | ||
"author": "Christian Amor Kvalheim <christkv@gmail.com>", | ||
@@ -23,3 +23,3 @@ "contributors": [], | ||
"bindings": "^1.2.1", | ||
"nan": "~2.0.9" | ||
"nan": "~2.4.0" | ||
}, | ||
@@ -26,0 +26,0 @@ "devDependencies": { |
130
README.md
@@ -1,37 +0,119 @@ | ||
# bson-ext | ||
# BSON parser | ||
[![linux build status](https://secure.travis-ci.org/imlucas/bson-ext.png)](http://travis-ci.org/imlucas/bson-ext) | ||
[![windows build status](https://ci.appveyor.com/api/projects/status/github/imlucas/bson-ext)](https://ci.appveyor.com/project/imlucas/bson-ext) | ||
If you don't yet know what BSON actually is, read [the spec](http://bsonspec.org). | ||
This module contains the BSON [native addon](https://nodejs.org/api/addons.html) | ||
only and is not meant to be used in isolation from the [bson](http://npm.im/bson) | ||
NPM module. It lives in it's own module so it can be an optional | ||
dependency for the [bson](http://npm.im/bson) module. | ||
To build a new version perform the following operation. | ||
## Testing | ||
``` | ||
npm test | ||
npm install | ||
npm run build | ||
``` | ||
## Prebuilt Binaries | ||
A simple example of how to use BSON in `node.js`: | ||
Have you ever seen this message in your console? | ||
```js | ||
// Get BSON parser class | ||
var BSON = require('bson-ext') | ||
// Get the Long type | ||
var Long = BSON.Long; | ||
// Create a bson parser instance, passing in all the types | ||
// This is needed so the C++ parser has references to the classes and can | ||
// use them to serialize and deserialize the types. | ||
var bson = new BSON(new BSON([BSON.Binary, BSON.Code, BSON.DBRef, BSON.Decimal128, BSON.Double, BSON.Int32, BSON.Long, BSON.Map, BSON.MaxKey, BSON.MinKey, BSON.ObjectId, BSON.BSONRegExp, BSON.Symbol, BSON.Timestamp])); | ||
// Serialize document | ||
var doc = { long: Long.fromNumber(100) } | ||
// Serialize a document | ||
var data = bson.serialize(doc) | ||
console.log('data:', data) | ||
// Deserialize the resulting Buffer | ||
var doc_2 = bson.deserialize(data) | ||
console.log('doc_2:', doc_2) | ||
``` | ||
js-bson: Failed to load c++ bson extension, using pure JS version | ||
``` | ||
We are experimenting with [node-pre-gyp](http://npm.im/node-pre-gyp) to publish | ||
and install prebuilt binaries. This means you don't need the full toolchain installed | ||
and configured correctly to use this module and you'll never have to see this | ||
message again. Currently, prebuilt binaries will only be used for Windows, | ||
as it is the most problematic platform for this issue. This will also allow us | ||
more time to evaluate the costs and benefits of prebuilt support on OSX and Linux. | ||
## Installation | ||
If you are interested in prebuilt binary support on OSX or Linux, please | ||
[join the discussion on this issue](https://github.com/christkv/bson-ext/issues/6)! | ||
`npm install bson-ext` | ||
## License | ||
## API | ||
Apache 2 | ||
### BSON types | ||
For all BSON types documentation, please refer to the documentation for the mongodb driver. | ||
https://github.com/mongodb/node-mongodb-native | ||
### BSON serialization and deserialiation | ||
**`new BSON()`** - Creates a new BSON seralizer/deserializer you can use to serialize and deserialize BSON. | ||
#### BSON.serialize | ||
The BSON serialize method takes a javascript object and an optional options object and returns a Node.js Buffer. | ||
* BSON.serialize(object, options) | ||
* @param {Object} object the Javascript object to serialize. | ||
* @param {Boolean} [options.checkKeys=false] the serializer will check if keys are valid. | ||
* @param {Boolean} [options.serializeFunctions=false] serialize the javascript. functions. | ||
* @param {Boolean} [options.ignoreUndefined=true] | ||
* @return {Buffer} returns a Buffer instance. | ||
#### BSON.serializeWithBufferAndIndex | ||
The BSON serializeWithBufferAndIndex method takes an object, a target buffer instance and an optional options object and returns the end serialization index in the final buffer. | ||
* BSON.serializeWithBufferAndIndex(object, buffer, options) | ||
* @param {Object} object the Javascript object to serialize. | ||
* @param {Buffer} buffer the Buffer you pre-allocated to store the serialized BSON object. | ||
* @param {Boolean} [options.checkKeys=false] the serializer will check if keys are valid. | ||
* @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions. | ||
* @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields. | ||
* @param {Number} [options.index=0] the index in the buffer where we wish to start serializing into. | ||
* @return {Number} returns the index pointing to the last written byte in the buffer. | ||
#### BSON.calculateObjectSize | ||
The BSON calculateObjectSize method takes a javascript object and an optional options object and returns the size of the BSON object. | ||
* BSON.calculateObjectSize(object, options) | ||
* @param {Object} object the Javascript object to serialize. | ||
* @param {Boolean} [options.serializeFunctions=false] serialize the javascript. functions. | ||
* @param {Boolean} [options.ignoreUndefined=true] | ||
* @return {Buffer} returns a Buffer instance. | ||
#### BSON.deserialize | ||
The BSON deserialize method takes a node.js Buffer and an optional options object and returns a deserialized Javascript object. | ||
* BSON.deserialize(buffer, options) | ||
* @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized. | ||
* @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. | ||
* @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function. | ||
* @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits | ||
* @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance. | ||
* @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types. | ||
* @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer. | ||
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. | ||
* @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents. | ||
#### BSON.deserializeStream | ||
The BSON deserializeStream method takes a node.js Buffer, startIndex and allow more control over deserialization of a Buffer containing concatenated BSON documents. | ||
* BSON.deserializeStream(buffer, startIndex, numberOfDocuments, documents, docStartIndex, options) | ||
* @param {Buffer} buffer the buffer containing the serialized set of BSON documents. | ||
* @param {Number} startIndex the start index in the data Buffer where the deserialization is to start. | ||
* @param {Number} numberOfDocuments number of documents to deserialize. | ||
* @param {Array} documents an array where to store the deserialized documents. | ||
* @param {Number} docStartIndex the index in the documents array from where to start inserting documents. | ||
* @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized. | ||
* @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. | ||
* @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function. | ||
* @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits | ||
* @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance. | ||
* @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types. | ||
* @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer. | ||
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. | ||
* @return {Object} returns the deserialized Javascript Object. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15425253
32
3365
1
120
+ Addednan@2.4.0(transitive)
- Removednan@2.0.9(transitive)
Updatednan@~2.4.0