https://github.com/meteor/js-bson
https://github.com/meteor/js-bson
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/meteor/js-bson
- Owner: meteor
- Created: 2013-07-18T17:53:54.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-02-07T01:50:58.000Z (over 10 years ago)
- Last Synced: 2025-03-28T17:54:37.040Z (2 months ago)
- Language: JavaScript
- Size: 768 KB
- Stars: 2
- Watchers: 18
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY
Awesome Lists containing this project
README
Javascript + C++ BSON parser
============================This BSON parser is primarily meant for usage with the `mongodb` node.js driver. However thanks to such wonderful tools at `onejs` we are able to package up a BSON parser that will work in the browser aswell. The current build is located in the `browser_build/bson.js` file.
A simple example on how to use it
function start() {
var BSON = bson().BSON;
var Long = bson().Long;var doc = {long: Long.fromNumber(100)}
// Serialize a document
var data = BSON.serialize(doc, false, true, false);
// De serialize it again
var doc_2 = BSON.deserialize(data);
}
It's got two simple methods to use in your application.
* BSON.serialize(object, checkKeys, asBuffer, serializeFunctions)
* @param {Object} object the Javascript object to serialize.
* @param {Boolean} checkKeys the serializer will check if keys are valid.
* @param {Boolean} asBuffer return the serialized object as a Buffer object **(ignore)**.
* @param {Boolean} serializeFunctions serialize the javascript functions **(default:false)**
* @return {TypedArray/Array} returns a TypedArray or Array depending on what your browser supports
* BSON.deserialize(buffer, options, isArray)
* Options
* **evalFunctions** {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
* **cacheFunctions** {Boolean, default:false}, cache evaluated functions for reuse.
* **cacheFunctionsCrc32** {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
* @param {TypedArray/Array} a TypedArray/Array containing the BSON data
* @param {Object} [options] additional options used for the deserialization.
* @param {Boolean} [isArray] ignore used for recursive parsing.
* @return {Object} returns the deserialized Javascript Object.