How to use the bson.Binary 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 mongodb / stitch-js-sdk / packages / core / services / aws-s3 / __tests__ / CoreAwsS3ServiceClientUnitTests.ts View on Github external
acl,
      contentType,
      bodyUintArray
    );
    expect(result.location).toEqual(expectedLocation);

    verify(
      serviceMock.callFunction(anything(), anything(), anything())
    ).times(4);
    const [funcNameArg4, funcArgsArg4, resultClassArg4]: any[] = capture(
      serviceMock.callFunction
    ).last();

    expect("put").toEqual(funcNameArg4);
    expect(1).toEqual(funcArgsArg4.length);
    expectedArgs.body = new BSON.Binary(new Buffer(bodyUintArray));
    expect(expectedArgs).toEqual(funcArgsArg4[0]);
    expect(ResultDecoders.PutObjectResultDecoder).toEqual(resultClassArg4);

    // Should pass along errors
    when(
      serviceMock.callFunction(anything(), anything(), anything())
    ).thenThrow(new Error("whoops"));

    try {
      await client.putObject(bucket, key, acl, contentType, body);
      fail();
    } catch (_) {
      // Do nothing
    }
  });
});
github cwbuecheler / node-tutorial-for-frontend-devs / node_modules / mongodb / lib / mongodb / gridfs / chunk.js View on Github external
var self = this;
  var mongoObjectFinal = mongoObject == null ? {} : mongoObject;
  this.writeConcern = writeConcern || {w:1};
  this.objectId = mongoObjectFinal._id == null ? new ObjectID() : mongoObjectFinal._id;
  this.chunkNumber = mongoObjectFinal.n == null ? 0 : mongoObjectFinal.n;
  this.data = new Binary();

  if(mongoObjectFinal.data == null) {
  } else if(typeof mongoObjectFinal.data == "string") {
    var buffer = new Buffer(mongoObjectFinal.data.length);
    buffer.write(mongoObjectFinal.data, 'binary', 0);
    this.data = new Binary(buffer);
  } else if(Array.isArray(mongoObjectFinal.data)) {
    var buffer = new Buffer(mongoObjectFinal.data.length);
    buffer.write(mongoObjectFinal.data.join(''), 'binary', 0);
    this.data = new Binary(buffer);
  } else if(mongoObjectFinal.data instanceof Binary || Object.prototype.toString.call(mongoObjectFinal.data) == "[object Binary]") {
    this.data = mongoObjectFinal.data;
  } else if(Buffer.isBuffer(mongoObjectFinal.data)) {
  } else {
    throw Error("Illegal chunk format");
  }
  // Update position
  this.internalPosition = 0;
};
github Hanul / UPPERCASE / UPPERCASE-DB / node_modules / mongodb-core / lib / auth / scram.js View on Github external
var executeScram = function(connection) {
      // Clean up the user
      username = username.replace('=', "=3D").replace(',', '=2C');

      // Create a random nonce
      var nonce = crypto.randomBytes(24).toString('base64');
      // var nonce = 'MsQUY9iw0T9fx2MUEz6LZPwGuhVvWAhc'
      var firstBare = f("n=%s,r=%s", username, nonce);

      // Build command structure
      var cmd = {
          saslStart: 1
        , mechanism: 'SCRAM-SHA-1'
        , payload: new Binary(f("n,,%s", firstBare))
        , autoAuthorize: 1
      }

      // Handle the error
      var handleError = function(err, r) {
        if(err) {
          numberOfValidConnections = numberOfValidConnections - 1;            
          errorObject = err; return false;
        } else if(r.result['$err']) {
          errorObject = r.result; return false;
        } else if(r.result['errmsg']) {
          errorObject = r.result; return false;
        } else {
          credentialsValid = true;
          numberOfValidConnections = numberOfValidConnections + 1;            
        }
github kevbook / Base-Node.js-App / node_modules / mongoose / node_modules / mongodb / lib / mongodb / gridfs / chunk.js View on Github external
var self = this;
  var mongoObjectFinal = mongoObject == null ? {} : mongoObject;

  this.objectId = mongoObjectFinal._id == null ? new ObjectID() : mongoObjectFinal._id;
  this.chunkNumber = mongoObjectFinal.n == null ? 0 : mongoObjectFinal.n;
  this.data = new Binary();

  if(mongoObjectFinal.data == null) {
  } else if(typeof mongoObjectFinal.data == "string") {
    var buffer = new Buffer(mongoObjectFinal.data.length);
    buffer.write(mongoObjectFinal.data, 'binary', 0);
    this.data = new Binary(buffer);
  } else if(Array.isArray(mongoObjectFinal.data)) {
    var buffer = new Buffer(mongoObjectFinal.data.length);
    buffer.write(mongoObjectFinal.data.join(''), 'binary', 0);
    this.data = new Binary(buffer);
  } else if(mongoObjectFinal.data instanceof Binary || Object.prototype.toString.call(mongoObjectFinal.data) == "[object Binary]") {    
    this.data = mongoObjectFinal.data;
  } else if(Buffer.isBuffer(mongoObjectFinal.data)) {
  } else {
    throw Error("Illegal chunk format");
  }
  // Update position
  this.internalPosition = 0;

  /**
   * The position of the read/write head
   * @name position
   * @lends Chunk#
   * @field
   */
  Object.defineProperty(this, "position", { enumerable: true
github kdelemme / budget-manager / api / node_modules / mongoose / node_modules / mongodb / lib / mongodb / auth / mongodb_plain.js View on Github external
var authenticate = function(db, username, password, options, callback) {
  var numberOfConnections = 0;
  var errorObject = null;
  
  if(options['connection'] != null) {
    //if a connection was explicitly passed on options, then we have only one...
    numberOfConnections = 1;
  } else {
    // Get the amount of connections in the pool to ensure we have authenticated all comments
    numberOfConnections = db.serverConfig.allRawConnections().length;
    options['onAll'] = true;
  }

  // Create payload
  var payload = new Binary(format("\x00%s\x00%s", username, password));

  // Let's start the sasl process
  var command = {
      saslStart: 1
    , mechanism: 'PLAIN'
    , payload: payload
    , autoAuthorize: 1
  };

  // Grab all the connections
  var connections = options['connection'] != null ? [options['connection']] : db.serverConfig.allRawConnections();

  // Authenticate all connections
  for(var i = 0; i < numberOfConnections; i++) {
    var connection = connections[i];
    // Execute first sasl step
github YoavGivati / salmon / node / node_modules / mongodb / lib / mongodb / auth / mongodb_scram.js View on Github external
// Generate server key
        var hmac = crypto.createHmac('sha1', saltedPassword);
        hmac.update(new Buffer('Server Key'))
        var serverKey = hmac.digest();

        // Generate server signature
        var hmac = crypto.createHmac('sha1', serverKey);
        hmac.update(new Buffer(authMsg))
        var serverSig = hmac.digest();

        //
        // Create continue message
        var cmd = {
            saslContinue: 1
          , conversationId: r.conversationId
          , payload: new Binary(new Buffer(clientFinal))
        }

        //
        // Execute sasl continue
        db.db(authdb).command(cmd, { connection: connection }, function(err, r) {
            if(r.done == false) {
              var cmd = {
                  saslContinue: 1
                , conversationId: r.conversationId
                , payload: new Buffer(0)
              }

              db.db(authdb).command(cmd, { connection: connection }, function(err, r) {
                handleEnd(err, r);
              });
            } else {
github mongodb-js / mongodb-core / lib2 / auth / plain.js View on Github external
var execute = function(connection) {
      // Create payload
      var payload = new Binary(f("\x00%s\x00%s", username, password));

      // Let's start the sasl process
      var command = {
          saslStart: 1
        , mechanism: 'PLAIN'
        , payload: payload
        , autoAuthorize: 1
      };

      // Let's start the process
      server(connection, new Query(self.bson, "$external.$cmd", command, {
        numberToSkip: 0, numberToReturn: 1
      }).toBin(), function(err, r) {
      // server.command("$external.$cmd"
      //   , command
      //   , { connection: connection }, function(err, r) {
github rueckstiess / mgeneratejs / lib / operators / binary.js View on Github external
module.exports = function(evaluator, options) {
  // default options
  options = evaluator(
    _.defaults(options, {
      length: 10,
      subtype: '00'
    })
  );
  return new bson.Binary(
    chance.string({ length: options.length }),
    options.subtype
  );
};
github NextCenturyCorporation / EVEREST / node_modules / mongoose / node_modules / mongodb / lib / mongodb / gridfs / chunk.js View on Github external
Chunk.prototype.rewind = function() {
  this.internalPosition = 0;
  this.data = new Binary();
};
github cwbuecheler / node-tutorial-for-frontend-devs / node_modules / mongodb / lib / mongodb / gridfs / chunk.js View on Github external
var Chunk = exports.Chunk = function(file, mongoObject, writeConcern) {
  if(!(this instanceof Chunk)) return new Chunk(file, mongoObject);

  this.file = file;
  var self = this;
  var mongoObjectFinal = mongoObject == null ? {} : mongoObject;
  this.writeConcern = writeConcern || {w:1};
  this.objectId = mongoObjectFinal._id == null ? new ObjectID() : mongoObjectFinal._id;
  this.chunkNumber = mongoObjectFinal.n == null ? 0 : mongoObjectFinal.n;
  this.data = new Binary();

  if(mongoObjectFinal.data == null) {
  } else if(typeof mongoObjectFinal.data == "string") {
    var buffer = new Buffer(mongoObjectFinal.data.length);
    buffer.write(mongoObjectFinal.data, 'binary', 0);
    this.data = new Binary(buffer);
  } else if(Array.isArray(mongoObjectFinal.data)) {
    var buffer = new Buffer(mongoObjectFinal.data.length);
    buffer.write(mongoObjectFinal.data.join(''), 'binary', 0);
    this.data = new Binary(buffer);
  } else if(mongoObjectFinal.data instanceof Binary || Object.prototype.toString.call(mongoObjectFinal.data) == "[object Binary]") {
    this.data = mongoObjectFinal.data;
  } else if(Buffer.isBuffer(mongoObjectFinal.data)) {
  } else {
    throw Error("Illegal chunk format");
  }