Skip to content

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 c43a34b commit 327da95
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/gridfs-stream/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var core = require('mongodb-core');
var crypto = require('crypto');
var stream = require('stream');
var util = require('util');
var Buffer = require('safe-buffer').Buffer;

var ERROR_NAMESPACE_NOT_FOUND = 26;

Expand Down
2 changes: 2 additions & 0 deletions lib/gridfs/chunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var Binary = require('mongodb-core').BSON.Binary,
ObjectID = require('mongodb-core').BSON.ObjectID;

var Buffer = require('safe-buffer').Buffer;

/**
* Class for representing a single chunk in GridFS.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/gridfs/grid_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
const Chunk = require('./chunk');
const ObjectID = require('mongodb-core').BSON.ObjectID;
const ReadPreference = require('mongodb-core').ReadPreference;
const Buffer = require('buffer').Buffer;
const Buffer = require('safe-buffer').Buffer;
const fs = require('fs');
const f = require('util').format;
const util = require('util');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"official"
],
"dependencies": {
"mongodb-core": "3.1.2"
"mongodb-core": "3.1.2",
"safe-buffer": "^5.1.2"
},
"devDependencies": {
"bluebird": "3.5.0",
Expand Down
1 change: 1 addition & 0 deletions test/functional/cursor_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const expect = require('chai').expect;
const Long = require('bson').Long;
const sinon = require('sinon');
const ReadPreference = require('mongodb-core').ReadPreference;
const Buffer = require('safe-buffer').Buffer;

describe('Cursor', function() {
before(function() {
Expand Down
1 change: 1 addition & 0 deletions test/functional/cursorstream_tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var expect = require('chai').expect;
var Buffer = require('safe-buffer').Buffer;

describe('Cursor Streams', function() {
before(function() {
Expand Down
1 change: 1 addition & 0 deletions test/functional/find_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const test = require('./shared').assert;
const setupDatabase = require('./shared').setupDatabase;
const expect = require('chai').expect;
const MongoClient = require('../../lib/mongo_client');
const Buffer = require('safe-buffer').Buffer;

describe('Find', function() {
before(function() {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/gridfs_stream_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const crypto = require('crypto'),
fs = require('fs'),
test = require('./shared').assert,
setupDatabase = require('./shared').setupDatabase,
expect = require('chai').expect;
expect = require('chai').expect,
Buffer = require('safe-buffer').Buffer;

describe('GridFS Stream', function() {
before(function() {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/gridfs_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const test = require('./shared').assert,
fs = require('fs'),
format = require('util').format,
child_process = require('child_process'),
expect = require('chai').expect;
expect = require('chai').expect,
Buffer = require('safe-buffer').Buffer;

describe('GridFS', function() {
before(function() {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/insert_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const test = require('./shared').assert,
setupDatabase = require('./shared').setupDatabase,
Script = require('vm'),
expect = require('chai').expect,
normalizedFunctionString = require('bson/lib/bson/parser/utils').normalizedFunctionString;
normalizedFunctionString = require('bson/lib/bson/parser/utils').normalizedFunctionString,
Buffer = require('safe-buffer').Buffer;

/**
* Module for parsing an ISO 8601 formatted string into a Date object.
Expand Down
3 changes: 2 additions & 1 deletion test/functional/operation_example_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
const test = require('./shared').assert,
setupDatabase = require('./shared').setupDatabase,
f = require('util').format,
expect = require('chai').expect;
expect = require('chai').expect,
Buffer = require('safe-buffer').Buffer;

describe('Operation Examples', function() {
before(function() {
Expand Down
1 change: 1 addition & 0 deletions test/functional/operation_generators_example_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var test = require('./shared').assert;
var setupDatabase = require('./shared').setupDatabase;
var Buffer = require('safe-buffer').Buffer;

/**************************************************************************
*
Expand Down
1 change: 1 addition & 0 deletions test/functional/operation_promises_example_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var fs = require('fs');
var f = require('util').format;
var test = require('./shared').assert;
var setupDatabase = require('./shared').setupDatabase;
var Buffer = require('safe-buffer').Buffer;

var delay = function(ms) {
return new Promise(function(resolve) {
Expand Down
2 changes: 1 addition & 1 deletion test/functional/promote_buffers_tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var test = require('./shared').assert;
var setupDatabase = require('./shared').setupDatabase;
var Buffer = require('buffer').Buffer;
var Buffer = require('safe-buffer').Buffer;

describe('Promote Buffers', function() {
before(function() {
Expand Down

0 comments on commit 327da95

Please sign in to comment.