How to use the bson.serialize 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 zapproject / zap-nodejs-api / src / oraclizer / server.js View on Github external
const midFile = storageDir + "mid-" + dateString(this.start);
        const lowFile = storageDir + "low-" + dateString(this.start);

        // Post the files to IPFS
        ipfs.files.add([
            {
                path: highFile,
                content: bson.serialize(this.pool.high)
            },
            {
                path: midFile,
                content: bson.serialize(this.pool.mid)
            },
            {
                path: lowFile,
                content: bson.serialize(this.pool.low)
            },

        ], (err, files) => {
            // Find the individual hashes
            let lowHash  = "";
            let midHash  = "";
            let highHash = "";

            // Load them from the IPFS results
            for ( const file of files ) {
                if ( file.path == highFile ) {
                    highHash = file.hash;
                }
                else if ( file.path == midFile ) {
                    midHash = file.hash;
                }
github zapproject / zap-nodejs-api / src / oraclizer / server.js View on Github external
const storageDir = this.storageFolder + "/merkle/";

        // File locations for individual levels
        const highFile = storageDir + "high-" + dateString(this.start);
        const midFile = storageDir + "mid-" + dateString(this.start);
        const lowFile = storageDir + "low-" + dateString(this.start);

        // Post the files to IPFS
        ipfs.files.add([
            {
                path: highFile,
                content: bson.serialize(this.pool.high)
            },
            {
                path: midFile,
                content: bson.serialize(this.pool.mid)
            },
            {
                path: lowFile,
                content: bson.serialize(this.pool.low)
            },

        ], (err, files) => {
            // Find the individual hashes
            let lowHash  = "";
            let midHash  = "";
            let highHash = "";

            // Load them from the IPFS results
            for ( const file of files ) {
                if ( file.path == highFile ) {
                    highHash = file.hash;
github zapproject / zap-nodejs-api / src / oraclizer / server.js View on Github external
const midMerkleTree = midMerkleTree.constructTree();
        const lowMerkleTree = lowMerkleTree.constructTree();

        // Store them
        const storageDir = this.storageFolder + "/merkle/";

        // File locations for individual levels
        const highFile = storageDir + "high-" + dateString(this.start);
        const midFile = storageDir + "mid-" + dateString(this.start);
        const lowFile = storageDir + "low-" + dateString(this.start);

        // Post the files to IPFS
        ipfs.files.add([
            {
                path: highFile,
                content: bson.serialize(this.pool.high)
            },
            {
                path: midFile,
                content: bson.serialize(this.pool.mid)
            },
            {
                path: lowFile,
                content: bson.serialize(this.pool.low)
            },

        ], (err, files) => {
            // Find the individual hashes
            let lowHash  = "";
            let midHash  = "";
            let highHash = "";
github axemclion / IndexedDBShim / test-support / webworker / webworker-util.js View on Github external
self.send = function (v, fd) {
        const ms = getMsgObj(v, fd);
        debug('Process ' + process.pid + ' sending message: ' + util.inspect(ms));

        s.send(BSON.serialize(ms), {binary: true, mask: true});
    };
github viddo / atom-textual-velocity / lib / NotesCache.js View on Github external
save(notes: Notes) {
    const cachePath = path.join(this._dir, CACHE_FILENAME);

    if (this._skipSave) {
      try {
        fs.unlinkSync(cachePath);
      } catch (err) {
        console.warn("textual-velocity: could not clear notes cache:", err);
      }
    } else {
      try {
        const data = BSON.serialize(notes);
        fs.writeFileSync(cachePath, data);
      } catch (err) {
        console.warn("textual-velocity: could not cache notes:", err);
      }
    }
  }
}
github sufish / IotHub_Server / services / notify_service.js View on Github external
static notifyCommandResp({productName, deviceName, command, requestId, ts, payload}){
        var data = bson.serialize({
            device_name: deviceName,
            command: command,
            request_id: requestId,
            send_at: ts,
            payload: payload
        })
        if(currentChannel != null){
            currentChannel.publish(commandRespExchange, productName, data)
        }
    }
github sufish / IotHub_Server / services / notify_service.js View on Github external
static notifyUpdateStatus({productName, deviceName, deviceStatus}){
        var data = bson.serialize({
            device_name: deviceName,
            device_status: deviceStatus
        })
        if(currentChannel != null) {
            currentChannel.publish(updateStatusExchange, productName, data, {
                persistent: true
            })
        }
    }
github sufish / IotHub_Server / services / notify_service.js View on Github external
static notifyUploadData(message) {
        var data = bson.serialize({
            device_name: message.device_name,
            payload: message.payload,
            send_at: message.sendAt,
            data_type: message.dataType,
            message_id: message.message_id
        })
        if(currentChannel != null) {
            currentChannel.publish(uploadDataExchange, message.product_name, data, {
                persistent: true
            })
        }
    }