diff --git a/.travis.yml b/.travis.yml index 8e2a51ea8..b4a9890d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,5 @@ node_js: - '6' - '5' - '4' + - '4.4.4' after_success: npm run coveralls diff --git a/index.js b/index.js index 2f5bfb074..b623ccdbc 100644 --- a/index.js +++ b/index.js @@ -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 || {}; @@ -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)); diff --git a/package.json b/package.json index e59a42248..6e500f2f6 100644 --- a/package.json +++ b/package.json @@ -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"