From 841ae961fbbe8fe12340723e1c6e897303ebee08 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 15 Nov 2018 19:39:47 +0100 Subject: [PATCH] [fix] Replace deprecated Buffer usage The `Buffer` constructor has been deprecated in favor of safer alternatives. See https://nodejs.org/en/docs/guides/buffer-constructor-deprecation/ --- README.md | 2 +- lib/server.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 480c4ce8f..332e99c33 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ var server = engine.listen(80); server.on('connection', function(socket){ socket.send('utf 8 string'); - socket.send(new Buffer([0, 1, 2, 3, 4, 5])); // binary data + socket.send(Buffer.from([0, 1, 2, 3, 4, 5])); // binary data }); ``` diff --git a/lib/server.js b/lib/server.js index 2ae3447e6..afc808a12 100644 --- a/lib/server.js +++ b/lib/server.js @@ -359,8 +359,7 @@ Server.prototype.handleUpgrade = function (req, socket, upgradeHead) { return; } - var head = new Buffer(upgradeHead.length); // eslint-disable-line node/no-deprecated-api - upgradeHead.copy(head); + var head = Buffer.from(upgradeHead); // eslint-disable-line node/no-deprecated-api upgradeHead = null; // delegate to ws