Skip to content

Avoid using deprecated Buffer constructor #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function WebSocketStream(target, protocols, options) {
}

if (coerceToBuffer && typeof chunk === 'string') {
chunk = new Buffer(chunk, 'utf8')
chunk = Buffer.from(chunk, 'utf8')
}
socket.send(chunk, next)
}
Expand All @@ -108,7 +108,7 @@ function WebSocketStream(target, protocols, options) {
}

if (coerceToBuffer && typeof chunk === 'string') {
chunk = new Buffer(chunk, 'utf8')
chunk = Buffer.from(chunk, 'utf8')
}

try {
Expand Down
5 changes: 3 additions & 2 deletions test-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var http = require('http')
var websocket = require('./')
var echo = require('./echo-server.js')
var WebSocketServer = require('ws').Server
var Buffer = require('safe-buffer').Buffer

echo.start(function(){
console.log('echo server is running')
Expand Down Expand Up @@ -44,9 +45,9 @@ function checkIfDataIsBinary () {
function waitFor (ws) {
ws.on('message', function (data) {
if (!Buffer.isBuffer(data)) {
ws.send(new Buffer('fail'))
ws.send(Buffer.from('fail'))
} else {
ws.send(new Buffer('success'))
ws.send(Buffer.from('success'))
}
})
}
Expand Down