Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
bson-buffer
Advanced tools
This is a fork with breaking changes!
This is a fork of the mongodb js-bson project located at https://github.com/mongodb/js-bson). The modifications are simple, but breaks compatibility with the original software.
See the BSON-buffer changes
section for more details.
If you don't yet know what BSON actually is, read the spec.
The browser version of the BSON parser is compiled using webpack and the current version is pre-compiled in the browser_build directory. To build a new version perform the following operation.
npm install
npm run build
A simple example of how to use BSON in the browser:
<script src="./browser_build/bson.js"></script>
<script>
function start() {
// Get the Long type
var Long = BSON.Long;
// Create a bson parser instance
var bson = new BSON();
// Serialize document
var doc = { long: Long.fromNumber(100) }
// Serialize a document
var data = bson.serialize(doc)
// De serialize it again
var doc_2 = bson.deserialize(data)
}
</script>
A simple example of how to use BSON in node.js
:
// Get BSON parser class
var BSON = require('bson')
// Get the Long type
var Long = BSON.Long;
// Create a bson parser instance
var bson = new BSON();
// Serialize document
var doc = { long: Long.fromNumber(100) }
// Serialize a document
var data = bson.serialize(doc)
console.log('data:', data)
// Deserialize the resulting Buffer
var doc_2 = bson.deserialize(data)
console.log('doc_2:', doc_2)
npm install bson-ext
For all BSON types documentation, please refer to the documentation for the mongodb driver.
https://github.com/mongodb/node-mongodb-native
new BSON()
- Creates a new BSON seralizer/deserializer you can use to serialize and deserialize BSON.
The BSON serialize method takes a javascript object and an optional options object and returns a Node.js Buffer.
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.
The BSON calculateObjectSize method takes a javascript object and an optional options object and returns the size of the BSON object.
The BSON deserialize method takes a node.js Buffer and an optional options object and returns a deserialized Javascript object.
The BSON deserializeStream method takes a node.js Buffer, startIndex and allow more control over deserialization of a Buffer containing concatenated BSON documents.
The purpose of this fork is to introduce direct conversion of BSON type Binary to Buffer and vice versa. In the browser it uses Uint8Array instead of Buffer, but the general idea is the same. This only works reliably if there is only need for a single subtype.
Example:
var in = { payload: new Buffer('00FF00FF00FF', 'hex') }
var ser = BSON.serialize(in);
var out = BSON.deserialize(ser);
Value of out
in this fork implementation
{ payload: Buffer } // '00FF00FF00FF'
Value of out
in original implementation
{ payload: {
_bsonType: 'Binary',
sub_type: BSON_BINARY_SUBTYPE_DEFAULT,
buffer: Buffer } } // '00FF00FF00FF'
FAQs
A bson parser for node.js and the browser
The npm package bson-buffer receives a total of 44 weekly downloads. As such, bson-buffer popularity was classified as not popular.
We found that bson-buffer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.