Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(buffer): use safe-buffer polyfill to maintain compatibility
Browse files Browse the repository at this point in the history
node.js < 4.5 and node.js < 5.9 doesn't support Buffer.alloc and Buffer.from
  • Loading branch information
Fonger authored and mbroadst committed Aug 20, 2018
1 parent 645d73d commit 728d897
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/auth/scram.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var f = require('util').format,
crypto = require('crypto'),
retrieveBSON = require('../connection/utils').retrieveBSON,
Query = require('../connection/commands').Query,
MongoError = require('../error').MongoError;
MongoError = require('../error').MongoError,
Buffer = require('safe-buffer').Buffer;

let saslprep;

Expand Down
1 change: 1 addition & 0 deletions lib/connection/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var retrieveBSON = require('./utils').retrieveBSON;
var BSON = retrieveBSON();
var Long = BSON.Long;
const MongoError = require('../error').MongoError;
const Buffer = require('safe-buffer').Buffer;

// Incrementing request id
var _requestId = 0;
Expand Down
3 changes: 2 additions & 1 deletion lib/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var inherits = require('util').inherits,
MongoNetworkError = require('../error').MongoNetworkError,
Logger = require('./logger'),
OP_COMPRESSED = require('../wireprotocol/shared').opcodes.OP_COMPRESSED,
MESSAGE_HEADER_SIZE = require('../wireprotocol/shared').MESSAGE_HEADER_SIZE;
MESSAGE_HEADER_SIZE = require('../wireprotocol/shared').MESSAGE_HEADER_SIZE,
Buffer = require('safe-buffer').Buffer;

var _id = 0;
var debugFields = [
Expand Down
1 change: 1 addition & 0 deletions lib/connection/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const uncompressibleCommands = require('../wireprotocol/compression').uncompress
const resolveClusterTime = require('../topologies/shared').resolveClusterTime;
const apm = require('./apm');
const defaultAuthProviders = require('../auth/defaultAuthProviders').defaultAuthProviders;
const Buffer = require('safe-buffer').Buffer;

var DISCONNECTED = 'disconnected';
var CONNECTING = 'connecting';
Expand Down
3 changes: 2 additions & 1 deletion lib/topologies/replset_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var inherits = require('util').inherits,
EventEmitter = require('events').EventEmitter,
Logger = require('../connection/logger'),
ReadPreference = require('./read_preference'),
MongoError = require('../error').MongoError;
MongoError = require('../error').MongoError,
Buffer = require('safe-buffer').Buffer;

var TopologyType = {
Single: 'Single',
Expand Down
1 change: 1 addition & 0 deletions lib/topologies/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const os = require('os');
const f = require('util').format;
const ReadPreference = require('./read_preference');
const Buffer = require('safe-buffer').Buffer;

/**
* Emit event if it exists
Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
],
"dependencies": {
"bson": "^1.1.0",
"require_optional": "^1.0.1"
"require_optional": "^1.0.1",
"safe-buffer": "^5.1.2"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
1 change: 1 addition & 0 deletions test/tests/functional/server_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Server = require('../../../lib/topologies/server');
const Bson = require('bson');
const Connection = require('../../../lib/connection/connection');
const mock = require('mongodb-mock-server');
const Buffer = require('safe-buffer').Buffer;

describe('Server tests', function() {
it('should correctly connect server to single instance', {
Expand Down
1 change: 1 addition & 0 deletions test/tests/unit/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const mock = require('mongodb-mock-server');
const ObjectId = require('bson').ObjectId;
const Timestamp = require('bson').Timestamp;
const Binary = require('bson').Binary;
const Buffer = require('safe-buffer').Buffer;

class ReplSetFixture {
constructor() {
Expand Down
1 change: 1 addition & 0 deletions test/tests/unit/scram_iterations_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const expect = require('chai').expect;
const mock = require('mongodb-mock-server');
const Server = require('../../../lib/topologies/server');
const Buffer = require('safe-buffer').Buffer;

describe('SCRAM Iterations Tests', function() {
const test = {};
Expand Down

0 comments on commit 728d897

Please sign in to comment.