Skip to content

Commit b028d39

Browse files
committed
chore: use standard 10 and Buffer.from
1 parent 84e3f70 commit b028d39

File tree

4 files changed

+135
-135
lines changed

4 files changed

+135
-135
lines changed

benchmark/index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ const HiredisParser = require('../test/hiredis')
1010
function returnError (error) {}
1111
function checkReply (error, res) {}
1212

13-
const startBuffer = new Buffer('$100\r\nabcdefghij')
14-
const chunkBuffer = new Buffer('abcdefghijabcdefghijabcdefghij')
15-
const stringBuffer = new Buffer('+testing a simple string\r\n')
16-
const integerBuffer = new Buffer(':1237884\r\n')
17-
const bigIntegerBuffer = new Buffer(':184467440737095516171234567890\r\n') // 2^64 + 1
18-
const errorBuffer = new Buffer('-Error ohnoesitbroke\r\n')
19-
const endBuffer = new Buffer('\r\n')
13+
const startBuffer = Buffer.from('$100\r\nabcdefghij')
14+
const chunkBuffer = Buffer.from('abcdefghijabcdefghijabcdefghij')
15+
const stringBuffer = Buffer.from('+testing a simple string\r\n')
16+
const integerBuffer = Buffer.from(':1237884\r\n')
17+
const bigIntegerBuffer = Buffer.from(':184467440737095516171234567890\r\n') // 2^64 + 1
18+
const errorBuffer = Buffer.from('-Error ohnoesitbroke\r\n')
19+
const endBuffer = Buffer.from('\r\n')
2020
const lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, ' +
2121
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' +
2222
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ' +
2323
'ut aliquip ex ea commodo consequat. Duis aute irure dolor in' // 256 chars
2424
const bigStringArray = (new Array(Math.pow(2, 16) / lorem.length).join(lorem + ' ')).split(' ') // Math.pow(2, 16) chars long
25-
const startBigBuffer = new Buffer('$' + (4 * 1024 * 1024) + '\r\n')
25+
const startBigBuffer = Buffer.from('$' + (4 * 1024 * 1024) + '\r\n')
2626

2727
const chunks = new Array(64)
2828
for (var i = 0; i < 64; i++) {
29-
chunks[i] = new Buffer(bigStringArray.join(' ') + '.') // Math.pow(2, 16) chars long
29+
chunks[i] = Buffer.from(bigStringArray.join(' ') + '.') // Math.pow(2, 16) chars long
3030
}
3131

3232
const arraySize = 100
@@ -38,24 +38,24 @@ for (i = 0; i < arraySize; i++) {
3838
array += size + '\r\n' + lorem.slice(0, size) + '\r\n'
3939
}
4040

41-
const arrayBuffer = new Buffer(array)
41+
const arrayBuffer = Buffer.from(array)
4242

4343
const bigArraySize = 160
44-
const bigArrayChunks = [new Buffer('*1\r\n*1\r\n*' + bigArraySize)]
44+
const bigArrayChunks = [Buffer.from('*1\r\n*1\r\n*' + bigArraySize)]
4545
for (i = 0; i < bigArraySize; i++) {
4646
// A chunk has a maximum size of 2^16 bytes.
4747
size = 65000 + i
4848
if (i % 2) {
4949
// The "x" in the beginning is important to prevent benchmark manipulation due to a minor jsparser optimization
50-
bigArrayChunks.push(new Buffer('x\r\n$' + size + '\r\n' + Array(size + 1).join('a') + '\r\n:' + (Math.random() * 1000000 | 0)))
50+
bigArrayChunks.push(Buffer.from('x\r\n$' + size + '\r\n' + Array(size + 1).join('a') + '\r\n:' + (Math.random() * 1000000 | 0)))
5151
} else {
52-
bigArrayChunks.push(new Buffer('\r\n+this is some short text about nothing\r\n:' + size + '\r\n$' + size + '\r\n' + Array(size).join('b')))
52+
bigArrayChunks.push(Buffer.from('\r\n+this is some short text about nothing\r\n:' + size + '\r\n$' + size + '\r\n' + Array(size).join('b')))
5353
}
5454
}
55-
bigArrayChunks.push(new Buffer('\r\n'))
55+
bigArrayChunks.push(Buffer.from('\r\n'))
5656

57-
const chunkedStringPart1 = new Buffer('+foobar')
58-
const chunkedStringPart2 = new Buffer('bazEND\r\n')
57+
const chunkedStringPart1 = Buffer.from('+foobar')
58+
const chunkedStringPart2 = Buffer.from('bazEND\r\n')
5959

6060
const options = {
6161
returnReply: checkReply,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"hiredis": "^0.5.0",
3636
"istanbul": "^0.4.0",
3737
"mocha": "^3.1.2",
38-
"standard": "^9.0.0"
38+
"standard": "^10.0.0"
3939
},
4040
"author": "Ruben Bridgewater",
4141
"license": "MIT",

test/errors.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('errors', function () {
1111
it('errors should have a stack trace with error message', function () {
1212
const err1 = new RedisError('test')
1313
const err2 = new ReplyError('test')
14-
const err3 = new ParserError('test', new Buffer(''), 0)
14+
const err3 = new ParserError('test', Buffer.from(''), 0)
1515
assert(err1.stack)
1616
assert(err2.stack)
1717
assert(err3.stack)

0 commit comments

Comments
 (0)