How to use the bson.deserialize function in bson

To help you get started, we’ve selected a few bson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hex7c0 / mongodb-backup / test / data.js View on Github external
docs.forEach(function(third) { // document

                var document = collection + '/' + third;
                assert.equal(extname(third), '.bson');
                var _id = third.split('.bson')[0];
                var data = BSON.deserialize(fs.readFileSync(document, {
                  encoding: null
                }));
                assert.deepEqual(data, DOCS[_id]);
                fs.unlinkSync(document);
              });
              fs.rmdirSync(collection);
github axemclion / IndexedDBShim / test-support / webworker / webworker-util.js View on Github external
s.on('message', function (ms) {
        debug('Process ' + process.pid + ' received message: ' + ms);

        const mo = BSON.deserialize(ms);

        // Ignore invalid messages; this is probably worth an error, though
        if (!isValidMessage(mo)) {
            return;
        }

        let fd;

        const fdSeq = mo[0];
        const msg = mo[1];

        // If our message has an associated file descriptor that we
        // have not yet received, queue it for later delivery.
        if (fdSeq) {
            if (!(fd = fdWaitingForMsg[fdSeq])) {
                msgWaitingForFd[fdSeq] = msg;
github hex7c0 / mongodb-backup / test / data.js View on Github external
assert.equal(fs.statSync(database).isDirectory(), true);
              var second = fs.readdirSync(database);
              assert.equal(second.length, 2);
              assert.equal(second[1], 'logins');
              fs.unlinkSync(database + '/.metadata/' + second[1]);
              var collection = database + '/' + second[1];
              if (fs.statSync(collection).isDirectory() === false) {
                return;
              }
              var docs = fs.readdirSync(collection);
              assert.equal(docs.length, 1, 'forget?');
              var third = docs[0];
              var document = collection + '/' + third;
              assert.equal(extname(third), '.bson');
              var _id = third.split('.bson')[0];
              var data = BSON.deserialize(fs.readFileSync(document, {
                encoding: null
              }));
              assert.deepEqual(data, DOCS[_id]);
              assert.equal(String(data._id), DOCS[Object.keys(DOCS)[0]]._id);
              fs.unlinkSync(document);
              fs.rmdirSync(collection);
              fs.rmdirSync(database + '/.metadata/');
              fs.rmdirSync(database);
            });
            done();
github sufish / IotHub_Server / samples / business_sim.js View on Github external
channel.consume(queue, function (msg) {
                    var data = bson.deserialize(msg.content)
                    console.log(`received from ${data.device_name}, status: ${data.device_status}`)
                    channel.ack(msg)
                })
            }
github sufish / IotHub_Server / samples / business_sim.js View on Github external
channel.consume(queue, function (msg) {
                    var data = bson.deserialize(msg.content)
                    console.log(`received from ${data.device_name}, messageId: ${data.message_id},payload: ${data.payload.toString()}`)
                    channel.ack(msg)
                })
github viddo / atom-textual-velocity / lib / NotesCache.js View on Github external
load(): Notes {
    atom.stateStore
      .save(atom.getStateKey(LEGACY_CUSTOM_STATE_KEY), {})
      .catch(() => {});

    const cachePath = path.join(this._dir, CACHE_FILENAME);
    try {
      return fs.existsSync(cachePath)
        ? BSON.deserialize(fs.readFileSync(cachePath))
        : {};
    } catch (error) {
      showWarningNotification("Failed to load notes cache", error);
      return {};
    }
  }
github sufish / IotHub_Server / event_handler.js View on Github external
channel.consume(queue, function (msg) {
        handlerFunc(bson.deserialize(msg.content))
        channel.ack(msg)
    })
}