Giter Site home page Giter Site logo

js-bson's Introduction

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

<head>
  <script src="https://raw.github.com/mongodb/js-bson/master/browser_build/bson.js">
  </script>
</head>
<body onload="start();">
<script>
  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);
  }
</script>
</body>

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.

js-bson's People

Contributors

aheckmann avatar christkv avatar clayzermk1 avatar defunctzombie avatar dwerner avatar forbeslindesay avatar jonathanong avatar jstewmon avatar kkoopa avatar kylepdavis avatar moredip avatar nailgun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.