Skip to content

Commit

Permalink
Use safe-buffer in place of new Buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Apr 7, 2017
1 parent 073a2cc commit c9312bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
"duplexify": "^3.2.0",
"inherits": "^2.0.1",
"readable-stream": "^2.2.0",
"safe-buffer": "^5.0.1",
"ws": "^2.2.3",
"xtend": "^4.0.0"
},
"devDependencies": {
"beefy": "^2.1.1",
"browserify": "^5.11.1",
"browserify": "^14.0.0",
"concat-stream": "^1.4.7",
"tape": "^2.14.0"
},
Expand Down
7 changes: 4 additions & 3 deletions stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var Transform = require('readable-stream').Transform
var duplexify = require('duplexify')
var WS = require('ws')
var Buffer = require('safe-buffer').Buffer

module.exports = WebSocketStream

Expand Down Expand Up @@ -154,8 +155,8 @@ function WebSocketStream(target, protocols, options) {

function onmessage(event) {
var data = event.data
if (data instanceof ArrayBuffer) data = new Buffer(new Uint8Array(data))
else data = new Buffer(data)
if (data instanceof ArrayBuffer) data = Buffer.from(new Uint8Array(data))
else data = Buffer.from(data, 'utf8')
proxy.push(data)
}

Expand All @@ -168,7 +169,7 @@ function WebSocketStream(target, protocols, options) {
var buffers = new Array(chunks.length)
for (var i = 0; i < chunks.length; i++) {
if (typeof chunks[i].chunk === 'string') {
buffers[i] = new Buffer(chunks[i], 'utf8') // TODO use safe-buffer
buffers[i] = Buffer.from(chunks[i], 'utf8')
} else {
buffers[i] = chunks[i].chunk
}
Expand Down

0 comments on commit c9312bd

Please sign in to comment.