Skip to content

Commit

Permalink
fix: dont use bl
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov authored and jacobheun committed Feb 7, 2019
1 parent 83aa996 commit 61f82f8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ exports.decode = () => {
const message = {
id: h >> 3,
type: h & 7,
data: new BufferList() // instead of allocating a new buff use a mem pool here
data: [] // instead of allocating a new buff use a mem pool here
}

state = States.READING
Expand All @@ -73,7 +73,8 @@ exports.decode = () => {
let left = length - msg.length
if (left < 0) { left = 0 }
if (msg.length > 0) {
data.append(msg.slice(0, length - left))
const buff = msg.slice(0, length - left)
data.push(Buffer.isBuffer(buff) ? buff : Buffer.from(buff))
}
if (left <= 0) { state = States.PARSING }
return [left, msg.slice(length - left), data]
Expand All @@ -98,7 +99,7 @@ exports.decode = () => {
if (States.READING === state) {
[length, msg, message.data] = read(msg, message.data, length)
if (length <= 0 && States.PARSING === state) {
message.data = message.data.slice() // get new buffer
message.data = Buffer.concat(message.data) // get new buffer
this.queue(message)
message = null
length = 0
Expand Down

0 comments on commit 61f82f8

Please sign in to comment.