Skip to content

Commit aa3f04b

Browse files
authored
Merge pull request #142 from ChALkeR/patch-1
Avoid using deprecated Buffer constructor
2 parents 48dc3dd + e69d128 commit aa3f04b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function WebSocketStream(target, protocols, options) {
9696
}
9797

9898
if (coerceToBuffer && typeof chunk === 'string') {
99-
chunk = new Buffer(chunk, 'utf8')
99+
chunk = Buffer.from(chunk, 'utf8')
100100
}
101101
socket.send(chunk, next)
102102
}
@@ -108,7 +108,7 @@ function WebSocketStream(target, protocols, options) {
108108
}
109109

110110
if (coerceToBuffer && typeof chunk === 'string') {
111-
chunk = new Buffer(chunk, 'utf8')
111+
chunk = Buffer.from(chunk, 'utf8')
112112
}
113113

114114
try {

test-server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var http = require('http')
22
var websocket = require('./')
33
var echo = require('./echo-server.js')
44
var WebSocketServer = require('ws').Server
5+
var Buffer = require('safe-buffer').Buffer
56

67
echo.start(function(){
78
console.log('echo server is running')
@@ -44,9 +45,9 @@ function checkIfDataIsBinary () {
4445
function waitFor (ws) {
4546
ws.on('message', function (data) {
4647
if (!Buffer.isBuffer(data)) {
47-
ws.send(new Buffer('fail'))
48+
ws.send(Buffer.from('fail'))
4849
} else {
49-
ws.send(new Buffer('success'))
50+
ws.send(Buffer.from('success'))
5051
}
5152
})
5253
}

0 commit comments

Comments
 (0)