Skip to content
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

Adopted safe-buffer #27

Merged
merged 1 commit into from
Apr 7, 2017
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
2 changes: 1 addition & 1 deletion benchmarks/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var max = 100000
var i
var start = Date.now()
var time
var buf = new Buffer('test')
var buf = Buffer.from('test')

for (i = 0; i < max; i++) {
mqtt.generate({
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/generateNet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var max = 1000000
var i = 0
var start = Date.now()
var time
var buf = new Buffer(10)
var buf = Buffer.allocUnsafe(10)
var net = require('net')
var server = net.createServer(handle)
var dest
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var start = Date.now() / 1000
var time

for (i = 0; i < max; i++) {
parser.parse(new Buffer([
parser.parse(Buffer.from([
48, 10, // Header (publish)
0, 4, // Topic length
116, 101, 115, 116, // Topic (test)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/writeToStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var max = 1000000
var i = 0
var start = Date.now()
var time
var buf = new Buffer(10)
var buf = Buffer.allocUnsafe(10)
var net = require('net')
var server = net.createServer(handle)
var dest
Expand Down
24 changes: 14 additions & 10 deletions constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
'use strict'

var Buffer = require('safe-buffer').Buffer

/* Protocol - protocol constants */
var protocol = module.exports

Expand Down Expand Up @@ -42,8 +46,8 @@ protocol.LENGTH_FIN_MASK = 0x80

/* Connack */
protocol.SESSIONPRESENT_MASK = 0x01
protocol.SESSIONPRESENT_HEADER = new Buffer([protocol.SESSIONPRESENT_MASK])
protocol.CONNACK_HEADER = new Buffer([protocol.codes['connack'] << protocol.CMD_SHIFT])
protocol.SESSIONPRESENT_HEADER = Buffer.from([protocol.SESSIONPRESENT_MASK])
protocol.CONNACK_HEADER = Buffer.from([protocol.codes['connack'] << protocol.CMD_SHIFT])

/* Connect */
protocol.USERNAME_MASK = 0x80
Expand All @@ -53,7 +57,7 @@ protocol.WILL_QOS_MASK = 0x18
protocol.WILL_QOS_SHIFT = 3
protocol.WILL_FLAG_MASK = 0x04
protocol.CLEAN_SESSION_MASK = 0x02
protocol.CONNECT_HEADER = new Buffer([protocol.codes['connect'] << protocol.CMD_SHIFT])
protocol.CONNECT_HEADER = Buffer.from([protocol.codes['connect'] << protocol.CMD_SHIFT])

function genHeader (type) {
return [0, 1, 2].map(function (qos) {
Expand Down Expand Up @@ -88,20 +92,20 @@ protocol.ACKS = {
pubrec: genHeader('pubrec')
}

protocol.SUBACK_HEADER = new Buffer([protocol.codes['suback'] << protocol.CMD_SHIFT])
protocol.SUBACK_HEADER = Buffer.from([protocol.codes['suback'] << protocol.CMD_SHIFT])

/* Protocol versions */
protocol.VERSION3 = new Buffer([3])
protocol.VERSION4 = new Buffer([4])
protocol.VERSION3 = Buffer.from([3])
protocol.VERSION4 = Buffer.from([4])

/* QoS */
protocol.QOS = [0, 1, 2].map(function (qos) {
return new Buffer([qos])
return Buffer.from([qos])
})

/* Empty packets */
protocol.EMPTY = {
pingreq: new Buffer([protocol.codes['pingreq'] << 4, 0]),
pingresp: new Buffer([protocol.codes['pingresp'] << 4, 0]),
disconnect: new Buffer([protocol.codes['disconnect'] << 4, 0])
pingreq: Buffer.from([protocol.codes['pingreq'] << 4, 0]),
pingresp: Buffer.from([protocol.codes['pingresp'] << 4, 0]),
disconnect: Buffer.from([protocol.codes['disconnect'] << 4, 0])
}
3 changes: 2 additions & 1 deletion generate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var writeToStream = require('./writeToStream')
var EE = require('events').EventEmitter
var inherits = require('inherits')
Expand Down Expand Up @@ -37,7 +38,7 @@ Accumulator.prototype.concat = function () {
length += lengths[i]
}

result = new Buffer(length)
result = Buffer.allocUnsafe(length)

for (i = 0; i < list.length && list[i]; i++) {
if (typeof list[i] !== 'string') {
Expand Down
3 changes: 2 additions & 1 deletion numbers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var max = 65536
var cache = {}
var buffer

for (var i = 0; i < max; i++) {
buffer = new Buffer(2)
buffer = Buffer.allocUnsafe(2)
buffer.writeUInt8(i >> 8, 0, true)
buffer.writeUInt8(i & 0x00FF, 0 + 1, true)
cache[i] = buffer
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
"dev-null": "^0.1.1",
"pre-commit": "^1.2.2",
"readable-stream": "^2.2.6",
"standard": "^9.0.1",
"standard": "^10.0.1",
"tap-spec": "^4.1.1",
"tape": "^4.6.3"
},
"dependencies": {
"bl": "^1.2.0",
"inherits": "^2.0.3",
"process-nextick-args": "^1.0.7"
"process-nextick-args": "^1.0.7",
"safe-buffer": "^5.0.1"
}
}
Loading