Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit 0b25e5b

Browse files
committed
First commit for bson-ext C++ extension
1 parent d78b2e6 commit 0b25e5b

33 files changed

+7046
-6
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,20 @@ node_modules
2626

2727
# Users Environment Variables
2828
.lock-wscript
29+
30+
.DS_Store
31+
*.swp
32+
*.seed
33+
.project
34+
.settings
35+
./data
36+
node_modules/
37+
38+
output
39+
build
40+
.bin
41+
npm-debug.log
42+
builderror.log
43+
44+
bson.sublime-project
45+
bson.sublime-workspace

HISTORY

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
0.2.21 2015-03-21
2+
-----------------
3+
- Updated Nan to 1.7.0 to support io.js and node 0.12.0
4+
5+
0.2.19 2015-02-16
6+
-----------------
7+
- Updated Nan to 1.6.2 to support io.js and node 0.12.0
8+
9+
0.2.18 2015-01-20
10+
-----------------
11+
- Updated Nan to 1.5.1 to support io.js
12+
13+
0.2.16 2014-12-17
14+
-----------------
15+
- Made pid cycle on 0xffff to avoid weird overflows on creation of ObjectID's
16+
17+
0.2.12 2014-08-24
18+
-----------------
19+
- Fixes for fortify review of c++ extension
20+
- toBSON correctly allows returns of non objects
21+
22+
0.2.3 2013-10-01
23+
----------------
24+
- Drying of ObjectId code for generation of id (Issue #54, https://github.com/moredip)
25+
- Fixed issue where corrupt CString's could cause endless loop
26+
- Support for Node 0.11.X > (Issue #49, https://github.com/kkoopa)
27+
28+
0.1.4 2012-09-25
29+
----------------
30+
- Added precompiled c++ native extensions for win32 ia32 and x64

LICENSE

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Apache License
1+
Apache License
22
Version 2.0, January 2004
33
http://www.apache.org/licenses/
44

@@ -178,15 +178,15 @@ Apache License
178178
APPENDIX: How to apply the Apache License to your work.
179179

180180
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "{}"
181+
boilerplate notice, with the fields enclosed by brackets "[]"
182182
replaced with your own identifying information. (Don't include
183183
the brackets!) The text should be enclosed in the appropriate
184184
comment syntax for the file format. We also recommend that a
185185
file or class name and description of purpose be included on the
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright [yyyy] [name of copyright owner]
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
@@ -199,4 +199,3 @@ Apache License
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202-

Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
NODE = node
2+
NPM = npm
3+
NODEUNIT = node_modules/nodeunit/bin/nodeunit
4+
5+
all: clean node_gyp
6+
7+
test: clean node_gyp
8+
npm test
9+
10+
node_gyp: clean
11+
node-gyp configure build
12+
13+
clean:
14+
node-gyp clean
15+
16+
browserify:
17+
node_modules/.bin/onejs build browser_build/package.json browser_build/bson.js
18+
19+
.PHONY: all

README.md

+69-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,69 @@
1-
# bson-ext
2-
The C++ bson parser for the node.js mongodb driver.
1+
Javascript + C++ BSON parser
2+
============================
3+
4+
This BSON parser is primarily meant to be used with the `mongodb` node.js driver.
5+
However, wonderful tools such as `onejs` can package up a BSON parser that will work in the browser.
6+
The current build is located in the `browser_build/bson.js` file.
7+
8+
A simple example of how to use BSON in the browser:
9+
10+
```html
11+
<html>
12+
<head>
13+
<script src="https://raw.github.com/mongodb/js-bson/master/browser_build/bson.js">
14+
</script>
15+
</head>
16+
<body onload="start();">
17+
<script>
18+
function start() {
19+
var BSON = bson().BSON;
20+
var Long = bson().Long;
21+
22+
var doc = {long: Long.fromNumber(100)}
23+
24+
// Serialize a document
25+
var data = BSON.serialize(doc, false, true, false);
26+
// De serialize it again
27+
var doc_2 = BSON.deserialize(data);
28+
}
29+
</script>
30+
</body>
31+
</html>
32+
```
33+
34+
A simple example of how to use BSON in `node.js`:
35+
36+
```javascript
37+
var bson = require("bson");
38+
var BSON = bson.BSONPure.BSON;
39+
var Long = bson.BSONPure.Long;
40+
41+
var doc = {long: Long.fromNumber(100)}
42+
43+
// Serialize a document
44+
var data = BSON.serialize(doc, false, true, false);
45+
console.log("data:", data);
46+
47+
// Deserialize the resulting Buffer
48+
var doc_2 = BSON.deserialize(data);
49+
console.log("doc_2:", doc_2);
50+
```
51+
52+
The API consists of two simple methods to serialize/deserialize objects to/from BSON format:
53+
54+
* BSON.serialize(object, checkKeys, asBuffer, serializeFunctions)
55+
* @param {Object} object the Javascript object to serialize.
56+
* @param {Boolean} checkKeys the serializer will check if keys are valid.
57+
* @param {Boolean} asBuffer return the serialized object as a Buffer object **(ignore)**.
58+
* @param {Boolean} serializeFunctions serialize the javascript functions **(default:false)**
59+
* @return {TypedArray/Array} returns a TypedArray or Array depending on what your browser supports
60+
61+
* BSON.deserialize(buffer, options, isArray)
62+
* Options
63+
* **evalFunctions** {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
64+
* **cacheFunctions** {Boolean, default:false}, cache evaluated functions for reuse.
65+
* **cacheFunctionsCrc32** {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
66+
* @param {TypedArray/Array} a TypedArray/Array containing the BSON data
67+
* @param {Object} [options] additional options used for the deserialization.
68+
* @param {Boolean} [isArray] ignore used for recursive parsing.
69+
* @return {Object} returns the deserialized Javascript Object.

binding.gyp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'bson',
5+
'sources': [ 'ext/bson.cc' ],
6+
'cflags!': [ '-fno-exceptions' ],
7+
'cflags_cc!': [ '-fno-exceptions' ],
8+
'include_dirs': [ '<!(node -e "require(\'nan\')")' ],
9+
'conditions': [
10+
['OS=="mac"', {
11+
'xcode_settings': {
12+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
13+
}
14+
}]
15+
]
16+
}
17+
]
18+
}

ext/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
./bson.node
3+
.lock-wscript

ext/Makefile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
NODE = node
2+
name = all
3+
JOBS = 1
4+
5+
all:
6+
rm -rf build .lock-wscript bson.node
7+
node-waf configure build
8+
cp -R ./build/Release/bson.node . || true
9+
10+
all_debug:
11+
rm -rf build .lock-wscript bson.node
12+
node-waf --debug configure build
13+
cp -R ./build/Release/bson.node . || true
14+
15+
clang:
16+
rm -rf build .lock-wscript bson.node
17+
CXX=clang node-waf configure build
18+
cp -R ./build/Release/bson.node . || true
19+
20+
clang_debug:
21+
rm -rf build .lock-wscript bson.node
22+
CXX=clang node-waf --debug configure build
23+
cp -R ./build/Release/bson.node . || true
24+
25+
clean:
26+
rm -rf build .lock-wscript bson.node
27+
28+
.PHONY: all

0 commit comments

Comments
 (0)