From 3d94b8cf18c695104ca195334dc75ff054c74eec Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Wed, 7 Dec 2016 02:28:40 -0800 Subject: [PATCH] fix(middleware): update `Buffer` usage Update Buffer usage to non-deprecated methods of creating a Buffer, polyfilling with `safer-buffer`. --- lib/middleware/common.js | 5 +++-- package.json | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/middleware/common.js b/lib/middleware/common.js index 3f2c9a9b5..49b009bfc 100644 --- a/lib/middleware/common.js +++ b/lib/middleware/common.js @@ -5,6 +5,7 @@ var mime = require('mime') var _ = require('lodash') var parseRange = require('range-parser') +var Buffer = require('safe-buffer').Buffer var log = require('../logger').create('web-server') @@ -40,10 +41,10 @@ var createServeFile = function (fs, directory, config) { return 200 } else if (range === -1) { // unsatisfiable range - responseData = new Buffer(0) + responseData = Buffer.alloc(0) return 416 } else if (range.type === 'bytes') { - responseData = new Buffer(responseData) + responseData = Buffer.from(responseData) if (range.length === 1) { var start = range[0].start var end = range[0].end diff --git a/package.json b/package.json index 3b8787d22..621b834d5 100644 --- a/package.json +++ b/package.json @@ -320,6 +320,7 @@ "qjobs": "^1.1.4", "range-parser": "^1.2.0", "rimraf": "^2.3.3", + "safe-buffer": "^5.0.1", "socket.io": "1.7.1", "source-map": "^0.5.3", "tmp": "0.0.28",