Skip to content

Commit

Permalink
use safe-buffer (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
reklatsmasters authored and floatdrop committed Dec 22, 2016
1 parent 8859a0f commit 53b11e3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_js:
- '6'
- '5'
- '4'
- '4.4.4'
after_success: npm run coveralls
11 changes: 2 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ const isRedirect = require('is-redirect');
const unzipResponse = require('unzip-response');
const createErrorClass = require('create-error-class');
const isRetryAllowed = require('is-retry-allowed');
const Buffer = require('safe-buffer').Buffer;
const pkg = require('./package');

const isModernBuffer = (
typeof Buffer.alloc === 'function' &&
typeof Buffer.allocUnsafe === 'function' &&
typeof Buffer.from === 'function'
);

function requestAsEventEmitter(opts) {
opts = opts || {};

Expand All @@ -46,9 +41,7 @@ function requestAsEventEmitter(opts) {
return;
}

const bufferString = isModernBuffer ?
Buffer.from(res.headers.location, 'binary').toString() :
new Buffer(res.headers.location, 'binary').toString();
const bufferString = Buffer.from(res.headers.location, 'binary').toString();

redirectUrl = urlLib.resolve(urlLib.format(opts), bufferString);
const redirectOpts = Object.assign({}, opts, urlLib.parse(redirectUrl));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"is-retry-allowed": "^1.0.0",
"is-stream": "^1.0.0",
"lowercase-keys": "^1.0.0",
"safe-buffer": "^5.0.1",
"timed-out": "^3.0.0",
"unzip-response": "^2.0.1",
"url-parse-lax": "^1.0.0"
Expand Down

0 comments on commit 53b11e3

Please sign in to comment.