You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-27Lines changed: 30 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,14 @@
1
1
# BSON parser
2
2
3
-
If you don't yet know what BSON actually is, read [the spec](http://bsonspec.org).
3
+
BSON is short for Binary JSON and is the binary-encoded serialization of JSON-like documents. You can learn more about it in [the specification](http://bsonspec.org).
4
4
5
-
The browser version of the BSON parser is compiled using webpack and the current
6
-
version is pre-compiled in the browser_build directory. To build a new version perform the following operation.
5
+
This browser version of the BSON parser is compiled using [webpack](https://webpack.js.org/) and the current version is pre-compiled in the `browser_build` directory.
6
+
7
+
This is the default BSON parser, however, there is a C++ Node.js addon version as well that does not support the browser. It can be found at [mongod-js/bson-ext](https://github.com/mongodb-js/bson-ext).
8
+
9
+
## Usage
10
+
11
+
To build a new version perform the following operations:
7
12
8
13
```
9
14
npm install
@@ -33,7 +38,7 @@ A simple example of how to use BSON in the browser:
33
38
</script>
34
39
```
35
40
36
-
A simple example of how to use BSON in `node.js`:
41
+
A simple example of how to use BSON in `Node.js`:
37
42
38
43
```js
39
44
// Get BSON parser class
@@ -63,68 +68,66 @@ console.log('doc_2:', doc_2)
63
68
64
69
### BSON types
65
70
66
-
For all BSON types documentation, please refer to the documentation for the mongodb driver.
67
-
68
-
https://github.com/mongodb/node-mongodb-native
71
+
For all BSON types documentation, please refer to the documentation for the [MongoDB Node.js driver](https://github.com/mongodb/node-mongodb-native).
69
72
70
73
### BSON serialization and deserialiation
71
74
72
-
**`new BSON()`** - Creates a new BSON seralizer/deserializer you can use to serialize and deserialize BSON.
75
+
**`new BSON()`** - Creates a new BSON serializer/deserializer you can use to serialize and deserialize BSON.
73
76
74
77
#### BSON.serialize
75
78
76
-
The BSON serialize method takes a javascript object and an optional options object and returns a Node.js Buffer.
79
+
The BSON `serialize` method takes a JavaScript object and an optional options object and returns a Node.js Buffer.
77
80
78
-
* BSON.serialize(object, options)
79
-
*@param {Object} object the Javascript object to serialize.
81
+
*`BSON.serialize(object, options)`
82
+
*@param {Object} object the JavaScript object to serialize.
80
83
*@param {Boolean} [options.checkKeys=false] the serializer will check if keys are valid.
81
-
*@param {Boolean} [options.serializeFunctions=false] serialize the javascript. functions.
84
+
*@param {Boolean} [options.serializeFunctions=false] serialize the JavaScript functions.
82
85
*@param {Boolean} [options.ignoreUndefined=true]
83
86
*@return {Buffer} returns a Buffer instance.
84
87
85
88
#### BSON.serializeWithBufferAndIndex
86
89
87
-
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.
90
+
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.
*@param {Number} [options.index=0] the index in the buffer where we wish to start serializing into.
96
99
*@return {Number} returns the index pointing to the last written byte in the buffer.
97
100
98
101
#### BSON.calculateObjectSize
99
102
100
-
The BSON calculateObjectSize method takes a javascript object and an optional options object and returns the size of the BSON object.
103
+
The BSON `calculateObjectSize` method takes a JavaScript object and an optional options object and returns the size of the BSON object.
101
104
102
-
* BSON.calculateObjectSize(object, options)
103
-
*@param {Object} object the Javascript object to serialize.
104
-
*@param {Boolean} [options.serializeFunctions=false] serialize the javascript. functions.
105
+
*`BSON.calculateObjectSize(object, options)`
106
+
*@param {Object} object the JavaScript object to serialize.
107
+
*@param {Boolean} [options.serializeFunctions=false] serialize the JavaScript functions.
105
108
*@param {Boolean} [options.ignoreUndefined=true]
106
109
*@return {Buffer} returns a Buffer instance.
107
110
108
111
#### BSON.deserialize
109
112
110
-
The BSON deserialize method takes a node.js Buffer and an optional options object and returns a deserialized Javascript object.
113
+
The BSON `deserialize` method takes a Node.js Buffer and an optional options object and returns a deserialized JavaScript object.
111
114
112
-
* BSON.deserialize(buffer, options)
115
+
*`BSON.deserialize(buffer, options)`
113
116
*@param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized.
114
117
*@param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse.
115
118
*@param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.
116
119
*@param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits
117
-
*@param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance.
120
+
*@param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a Node.js Buffer instance.
118
121
*@param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.
119
122
*@param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.
120
123
*@param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.
121
124
*@return {Number} returns the next index in the buffer after deserialization **x** numbers of documents.
122
125
123
126
#### BSON.deserializeStream
124
127
125
-
The BSON deserializeStream method takes a node.js Buffer, startIndex and allow more control over deserialization of a Buffer containing concatenated BSON documents.
128
+
The BSON `deserializeStream` method takes a Node.js Buffer, `startIndex` and allow more control over deserialization of a Buffer containing concatenated BSON documents.
0 commit comments