Skip to content

Commit

Permalink
Update dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jul 17, 2017
1 parent 7308cc0 commit dc584b6
Show file tree
Hide file tree
Showing 40 changed files with 188 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_js:
- "0.12"
- "4"
- "6"
- "7"
- "8"
5 changes: 4 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var msgpack = require('./')() // namespace our extensions
var a = new MyType(2, 'a')
var encode = msgpack.encode
Expand All @@ -22,7 +25,7 @@ function MyType (size, value) {
}

function mytipeEncode (obj) {
var buf = new Buffer(obj.size)
var buf = Buffer.allocUnsafe(obj.size)
buf.fill(obj.value)
return buf
}
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var assert = require('assert')
var bl = require('bl')
var streams = require('./lib/streams')
Expand Down Expand Up @@ -47,7 +50,7 @@ function msgpack (options) {

function reEncode (obj) {
var buf = bl()
var header = new Buffer(1)
var header = Buffer.allocUnsafe(1)

header.writeInt8(type, 0)

Expand Down
59 changes: 31 additions & 28 deletions lib/encoder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var bl = require('bl')
var TOLERANCE = 0.1

Expand All @@ -9,35 +12,35 @@ module.exports = function buildEncode (encodingTypes, forceFloat64, compatibilit
if (obj === undefined) {
throw new Error('undefined is not encodable in msgpack!')
} else if (obj === null) {
buf = new Buffer(1)
buf = Buffer.allocUnsafe(1)
buf[0] = 0xc0
} else if (obj === true) {
buf = new Buffer(1)
buf = Buffer.allocUnsafe(1)
buf[0] = 0xc3
} else if (obj === false) {
buf = new Buffer(1)
buf = Buffer.allocUnsafe(1)
buf[0] = 0xc2
} else if (typeof obj === 'string') {
len = Buffer.byteLength(obj)
if (len < 32) {
buf = new Buffer(1 + len)
buf = Buffer.allocUnsafe(1 + len)
buf[0] = 0xa0 | len
if (len > 0) {
buf.write(obj, 1)
}
} else if (len <= 0xff && !compatibilityMode) {
// str8, but only when not in compatibility mode
buf = new Buffer(2 + len)
buf = Buffer.allocUnsafe(2 + len)
buf[0] = 0xd9
buf[1] = len
buf.write(obj, 2)
} else if (len <= 0xffff) {
buf = new Buffer(3 + len)
buf = Buffer.allocUnsafe(3 + len)
buf[0] = 0xda
buf.writeUInt16BE(len, 1)
buf.write(obj, 3)
} else {
buf = new Buffer(5 + len)
buf = Buffer.allocUnsafe(5 + len)
buf[0] = 0xdb
buf.writeUInt32BE(len, 1)
buf.write(obj, 5)
Expand All @@ -46,30 +49,30 @@ module.exports = function buildEncode (encodingTypes, forceFloat64, compatibilit
// weird hack to support Buffer
// and Buffer-like objects
if (obj.length <= 0xff) {
buf = new Buffer(2)
buf = Buffer.allocUnsafe(2)
buf[0] = 0xc4
buf[1] = obj.length
} else if (obj.length <= 0xffff) {
buf = new Buffer(3)
buf = Buffer.allocUnsafe(3)
buf[0] = 0xc5
buf.writeUInt16BE(obj.length, 1)
} else {
buf = new Buffer(5)
buf = Buffer.allocUnsafe(5)
buf[0] = 0xc6
buf.writeUInt32BE(obj.length, 1)
}

buf = bl([buf, obj])
} else if (Array.isArray(obj)) {
if (obj.length < 16) {
buf = new Buffer(1)
buf = Buffer.allocUnsafe(1)
buf[0] = 0x90 | obj.length
} else if (obj.length < 65536) {
buf = new Buffer(3)
buf = Buffer.allocUnsafe(3)
buf[0] = 0xdc
buf.writeUInt16BE(obj.length, 1)
} else {
buf = new Buffer(5)
buf = Buffer.allocUnsafe(5)
buf[0] = 0xdd
buf.writeUInt32BE(obj.length, 1)
}
Expand All @@ -85,45 +88,45 @@ module.exports = function buildEncode (encodingTypes, forceFloat64, compatibilit
return encodeFloat(obj, forceFloat64)
} else if (obj >= 0) {
if (obj < 128) {
buf = new Buffer(1)
buf = Buffer.allocUnsafe(1)
buf[0] = obj
} else if (obj < 256) {
buf = new Buffer(2)
buf = Buffer.allocUnsafe(2)
buf[0] = 0xcc
buf[1] = obj
} else if (obj < 65536) {
buf = new Buffer(3)
buf = Buffer.allocUnsafe(3)
buf[0] = 0xcd
buf.writeUInt16BE(obj, 1)
} else if (obj <= 0xffffffff) {
buf = new Buffer(5)
buf = Buffer.allocUnsafe(5)
buf[0] = 0xce
buf.writeUInt32BE(obj, 1)
} else if (obj <= 9007199254740991) {
buf = new Buffer(9)
buf = Buffer.allocUnsafe(9)
buf[0] = 0xcf
write64BitUint(buf, obj)
} else {
return encodeFloat(obj, true)
}
} else {
if (obj >= -32) {
buf = new Buffer(1)
buf = Buffer.allocUnsafe(1)
buf[0] = 0x100 + obj
} else if (obj >= -128) {
buf = new Buffer(2)
buf = Buffer.allocUnsafe(2)
buf[0] = 0xd0
buf.writeInt8(obj, 1)
} else if (obj >= -32768) {
buf = new Buffer(3)
buf = Buffer.allocUnsafe(3)
buf[0] = 0xd1
buf.writeInt16BE(obj, 1)
} else if (obj > -214748365) {
buf = new Buffer(5)
buf = Buffer.allocUnsafe(5)
buf[0] = 0xd2
buf.writeInt32BE(obj, 1)
} else if (obj >= -9007199254740991) {
buf = new Buffer(9)
buf = Buffer.allocUnsafe(9)
buf[0] = 0xd3
write64BitInt(buf, 1, obj)
} else {
Expand Down Expand Up @@ -189,7 +192,7 @@ module.exports = function buildEncode (encodingTypes, forceFloat64, compatibilit
headers.push(length & 0x000000ff)
}

return bl().append(new Buffer(headers)).append(encoded)
return bl().append(Buffer.from(headers)).append(encoded)
}

function encodeObject (obj) {
Expand All @@ -209,10 +212,10 @@ module.exports = function buildEncode (encodingTypes, forceFloat64, compatibilit
}

if (length < 16) {
header = new Buffer(1)
header = Buffer.allocUnsafe(1)
header[0] = 0x80 | length
} else {
header = new Buffer(3)
header = Buffer.allocUnsafe(3)
header[0] = 0xde
header.writeUInt16BE(length, 1)
}
Expand Down Expand Up @@ -266,14 +269,14 @@ function isFloat (n) {
function encodeFloat (obj, forceFloat64) {
var buf

buf = new Buffer(5)
buf = Buffer.allocUnsafe(5)
buf[0] = 0xca
buf.writeFloatBE(obj, 1)

// FIXME is there a way to check if a
// value fits in a float?
if (forceFloat64 || Math.abs(obj - buf.readFloatBE(1)) > TOLERANCE) {
buf = new Buffer(9)
buf = Buffer.allocUnsafe(9)
buf[0] = 0xcb
buf.writeDoubleBE(obj, 1)
}
Expand Down
2 changes: 2 additions & 0 deletions lib/streams.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var Transform = require('readable-stream').Transform
var inherits = require('inherits')
var bl = require('bl')
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
},
"homepage": "https://github.com/mcollina/msgpack5",
"devDependencies": {
"browserify": "^10.2.4",
"browserify": "^14.0.0",
"faucet": "0.0.1",
"jshint": "^2.5.2",
"level-test": "^2.0.0",
"pre-commit": "1.0.10",
"standard": "^8.0.0",
"tape": "^4.0.0",
"jshint": "^2.9.5",
"level-test": "^2.0.3",
"pre-commit": "^1.2.2",
"standard": "^10.0.0",
"tape": "^4.7.0",
"testling": "^1.7.1",
"uglify-js": "^2.4.15"
"uglify-js": "^3.0.0"
},
"standard": {
"ignore": [
Expand All @@ -60,8 +60,9 @@
]
},
"dependencies": {
"bl": "^1.0.0",
"inherits": "^2.0.1",
"readable-stream": "^2.0.1"
"bl": "^1.2.1",
"inherits": "^2.0.3",
"readable-stream": "^2.3.3",
"safe-buffer": "^5.1.1"
}
}
11 changes: 6 additions & 5 deletions test/1-byte-length-buffers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')

function build (size) {
var buf

buf = new Buffer(size)
buf = Buffer.allocUnsafe(size)
buf.fill('a')

return buf
Expand All @@ -20,7 +21,7 @@ test('encode/decode 2^8-1 bytes buffers', function (t) {
all.push(build(Math.pow(2, 8) - 1))
all.push(build(Math.pow(2, 6) + 1))
all.push(build(1))
all.push(new Buffer(0))
all.push(Buffer.allocUnsafe(0))

all.forEach(function (orig) {
t.test('encoding a buffer of length ' + orig.length, function (t) {
Expand All @@ -33,7 +34,7 @@ test('encode/decode 2^8-1 bytes buffers', function (t) {
})

t.test('decoding a buffer of length ' + orig.length, function (t) {
var buf = new Buffer(2 + orig.length)
var buf = Buffer.allocUnsafe(2 + orig.length)
buf[0] = 0xc4
buf[1] = orig.length
orig.copy(buf, 2)
Expand All @@ -53,7 +54,7 @@ test('encode/decode 2^8-1 bytes buffers', function (t) {
test('decoding a chopped 2^8-1 bytes buffer', function (t) {
var encoder = msgpack()
var orig = build(Math.pow(2, 6))
var buf = new Buffer(2 + orig.length)
var buf = Buffer.allocUnsafe(2 + orig.length)
buf[0] = 0xc4
buf[1] = Math.pow(2, 8) - 1 // set bigger size
orig.copy(buf, 2)
Expand All @@ -68,7 +69,7 @@ test('decoding a chopped 2^8-1 bytes buffer', function (t) {

test('decoding an incomplete header of 2^8-1 bytes buffer', function (t) {
var encoder = msgpack()
var buf = new Buffer(1)
var buf = Buffer.allocUnsafe(1)
buf[0] = 0xc4
buf = bl().append(buf)
var origLength = buf.length
Expand Down
7 changes: 4 additions & 3 deletions test/1-byte-length-exts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
Expand All @@ -14,7 +15,7 @@ test('encode/decode variable ext data up to 0xff', function (t) {
}

function mytipeEncode (obj) {
var buf = new Buffer(obj.size)
var buf = Buffer.allocUnsafe(obj.size)
buf.fill(obj.value)
return buf
}
Expand Down Expand Up @@ -72,7 +73,7 @@ test('encode/decode variable ext data up to 0xff', function (t) {

t.test('decoding an incomplete variable ext data up to 0xff', function (t) {
var obj = encoder.encode(new MyType(250, 'a'))
var buf = new Buffer(obj.length)
var buf = Buffer.allocUnsafe(obj.length)
buf[0] = 0xc7
buf.writeUInt8(obj.length + 2, 1) // set bigger size
obj.copy(buf, 2, 2, obj.length)
Expand All @@ -86,7 +87,7 @@ test('encode/decode variable ext data up to 0xff', function (t) {
})

t.test('decoding an incomplete header of variable ext data up to 0xff', function (t) {
var buf = new Buffer(2)
var buf = Buffer.allocUnsafe(2)
buf[0] = 0xc7
buf = bl().append(buf)
var origLength = buf.length
Expand Down
7 changes: 4 additions & 3 deletions test/1-byte-length-strings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
Expand Down Expand Up @@ -28,7 +29,7 @@ test('encode/decode 32 <-> (2^8-1) bytes strings', function (t) {
})

t.test('decoding a string of length ' + str.length, function (t) {
var buf = new Buffer(2 + Buffer.byteLength(str))
var buf = Buffer.allocUnsafe(2 + Buffer.byteLength(str))
buf[0] = 0xd9
buf[1] = Buffer.byteLength(str)
buf.write(str, 2)
Expand All @@ -50,7 +51,7 @@ test('decoding a chopped string', function (t) {
var str
for (str = 'a'; str.length < 40; str += 'a') {
}
var buf = new Buffer(2 + Buffer.byteLength(str))
var buf = Buffer.allocUnsafe(2 + Buffer.byteLength(str))
buf[0] = 0xd9
buf[1] = Buffer.byteLength(str) + 10 // set bigger size
buf.write(str, 2)
Expand All @@ -65,7 +66,7 @@ test('decoding a chopped string', function (t) {

test('decoding an incomplete header of a string', function (t) {
var encoder = msgpack()
var buf = new Buffer(1)
var buf = Buffer.allocUnsafe(1)
buf[0] = 0xd9
buf = bl().append(buf)
var origLength = buf.length
Expand Down
3 changes: 2 additions & 1 deletion test/15-elements-arrays.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

var Buffer = require('safe-buffer').Buffer
var test = require('tape').test
var msgpack = require('../')
var bl = require('bl')
Expand Down Expand Up @@ -65,7 +66,7 @@ test('decoding an incomplete array', function (t) {

var array = ['a', 'b', 'c']
var size = computeLength(array)
var buf = new Buffer(size)
var buf = Buffer.allocUnsafe(size)
buf[0] = 0x90 | array.length + 2 // set bigger size
var pos = 1
for (var i = 0; i < array.length; i++) {
Expand Down
Loading

0 comments on commit dc584b6

Please sign in to comment.