Skip to content

Commit 2614834

Browse files
committed
use Buffer.from pony fill to restore support for node.js v4.0-4.5
This is particularly helpful on AWS lambda where the only avaliable node.js version is 4.3 FWIW, Bluemix OpenWhisk doesn't have this problem ;)
1 parent ae085e0 commit 2614834

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/base_service.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const extend = require('extend');
1919
const vcapServices = require('vcap_services');
2020
const helper = require('./helper');
2121
const request = require('request');
22+
const bufferFrom = require('buffer-from'); // new Buffer() is deprecated, replaced with Buffer.from() in node v4.5.0+ - this uses the new api when possible but falls back to the old one otherwise
2223

2324
/**
2425
* Internal base class that other services inherit from
@@ -74,7 +75,7 @@ BaseService.prototype.initCredentials = function(options) {
7475

7576
// Calculate and add Authorization header to base options
7677
const authHeader = {
77-
Authorization: 'Basic ' + Buffer.from(options.username + ':' + options.password).toString('base64')
78+
Authorization: 'Basic ' + bufferFrom(options.username + ':' + options.password).toString('base64')
7879
};
7980
options.headers = extend(authHeader, options.headers);
8081
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
},
8888
"dependencies": {
8989
"async": "^2.0.1",
90+
"buffer-from": "^0.1.1",
9091
"cookie": "~0.3.1",
9192
"csv-stringify": "~1.0.2",
9293
"extend": "~3.0.0",
@@ -100,7 +101,7 @@
100101
"websocket": "~1.0.22"
101102
},
102103
"engines": {
103-
"node": ">=4.5.0"
104+
"node": ">=4"
104105
},
105106
"scripts": {
106107
"test": "npm run lint && mocha test/unit test/integration",

0 commit comments

Comments
 (0)