Comparing version 0.3.2 to 0.4.0
@@ -5,3 +5,3 @@ /** | ||
*/ | ||
if(typeof window === 'undefined') { | ||
if(typeof window === 'undefined') { | ||
var Buffer = require('buffer').Buffer; // TODO just use global Buffer | ||
@@ -12,3 +12,3 @@ } | ||
* A class representation of the BSON Binary type. | ||
* | ||
* | ||
* Sub types | ||
@@ -29,3 +29,3 @@ * - **BSON.BSON_BINARY_SUBTYPE_DEFAULT**, default BSON type. | ||
if(!(this instanceof Binary)) return new Binary(buffer, subType); | ||
this._bsontype = 'Binary'; | ||
@@ -36,3 +36,3 @@ | ||
this.position = 0; | ||
} else { | ||
} else { | ||
this.sub_type = subType == null ? BSON_BINARY_SUBTYPE_DEFAULT : subType; | ||
@@ -54,3 +54,3 @@ this.position = 0; | ||
} else { | ||
this.buffer = buffer; | ||
this.buffer = buffer; | ||
} | ||
@@ -60,3 +60,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 +82,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 +93,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 +112,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 +119,3 @@ for(var i = 0; i < this.buffer.length; i++) { | ||
} | ||
// Reassign the buffer | ||
@@ -144,5 +144,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 +156,3 @@ // Create a new buffer | ||
} | ||
// Assign the new buffer | ||
@@ -167,10 +167,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 +199,3 @@ this.position = offset > this.position ? offset : this.position; | ||
: this.position; | ||
// Let's return the data based on the type we have | ||
@@ -222,3 +222,3 @@ if(this.buffer['slice']) { | ||
Binary.prototype.value = function value(asRaw) { | ||
asRaw = asRaw == null ? false : asRaw; | ||
asRaw = asRaw == null ? false : asRaw; | ||
@@ -228,3 +228,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 +280,3 @@ if(typeof Buffer != 'undefined' && Buffer.isBuffer(this.buffer)) { | ||
* Binary default subtype | ||
* @ignore | ||
* @ignore | ||
*/ | ||
@@ -294,3 +294,3 @@ var BSON_BINARY_SUBTYPE_DEFAULT = 0; | ||
buffer[i] = data.charCodeAt(i); | ||
} | ||
} | ||
// Write the string to the buffer | ||
@@ -310,3 +310,3 @@ return buffer; | ||
} | ||
return result; | ||
return result; | ||
}; | ||
@@ -318,3 +318,3 @@ | ||
* Default BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -325,3 +325,3 @@ **/ | ||
* Function BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -332,3 +332,3 @@ **/ | ||
* Byte Array BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -339,3 +339,3 @@ **/ | ||
* OLD UUID BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -346,3 +346,3 @@ **/ | ||
* UUID BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -353,3 +353,3 @@ **/ | ||
* MD5 BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -360,3 +360,3 @@ **/ | ||
* User BSON type | ||
* | ||
* | ||
* @classconstant SUBTYPE_DEFAULT | ||
@@ -370,2 +370,2 @@ **/ | ||
module.exports = Binary; | ||
module.exports.Binary = Binary; | ||
module.exports.Binary = Binary; |
@@ -5,2 +5,3 @@ try { | ||
} catch(err) { | ||
console.dir(err) | ||
// do nothing | ||
@@ -72,3 +73,3 @@ } | ||
}); | ||
// Catch error and return no classes found | ||
@@ -75,0 +76,0 @@ try { |
@@ -113,3 +113,3 @@ /** | ||
} | ||
var time4Bytes = BinaryParser.encodeInt(time, 32, true, true); | ||
@@ -275,2 +275,2 @@ /* for time-based ObjectID the bytes following the time will be zeroed */ | ||
module.exports.ObjectID = ObjectID; | ||
module.exports.ObjectId = ObjectID; | ||
module.exports.ObjectId = ObjectID; |
{ "name" : "bson" | ||
, "description" : "A bson parser for node.js and the browser" | ||
, "keywords" : ["mongodb", "bson", "parser"] | ||
, "version" : "0.3.2" | ||
, "version" : "0.4.0" | ||
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>" | ||
@@ -16,6 +16,5 @@ , "contributors" : [] | ||
, "one": "2.X.X" | ||
, "benchmark": "1.0.0" | ||
, "colors": "1.1.0" | ||
} | ||
, "optionalDependencies": { | ||
"bson-ext": "~0.1" | ||
} | ||
, "config": { "native" : false } | ||
@@ -26,3 +25,3 @@ , "main": "./lib/bson/index" | ||
, "scripts": { | ||
"test" : "nodeunit ./test/node && TEST_NATIVE=TRUE nodeunit ./test/node" | ||
"test" : "nodeunit ./test/node" | ||
} | ||
@@ -29,0 +28,0 @@ , "browser": "lib/bson/bson.js" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
411121
0
27
10727
5
6