Skip to content

Commit 8e24ac9

Browse files
committed
Only Node v4 or greater
1 parent 71fc5bb commit 8e24ac9

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "0.10"
5-
- "0.11"
6-
- "0.12"
74
- "4"
85
- "5"
96
- "6"

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function throwIfNotStringOrBuffer (val, prefix) {
1111
function HashBase (blockSize) {
1212
Transform.call(this)
1313

14-
this._block = new Buffer(blockSize)
14+
this._block = Buffer.allocUnsafe(blockSize)
1515
this._blockSize = blockSize
1616
this._blockOffset = 0
1717
this._length = [0, 0, 0, 0]
@@ -46,7 +46,7 @@ HashBase.prototype._flush = function (callback) {
4646
HashBase.prototype.update = function (data, encoding) {
4747
throwIfNotStringOrBuffer(data, 'Data')
4848
if (this._finalized) throw new Error('Digest already called')
49-
if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding)
49+
if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
5050

5151
// consume data
5252
var block = this._block

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@
3333
"nyc": "^8.3.2",
3434
"standard": "*",
3535
"tape": "^4.2.0"
36+
},
37+
"engines": {
38+
"node": ">=4"
3639
}
3740
}

test/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var test = require('tape')
33
var HashBase = require('../')
44

55
var utf8text = 'УТФ-8 text'
6-
var utf8buf = new Buffer(utf8text, 'utf8')
6+
var utf8buf = Buffer.from(utf8text, 'utf8')
77
function noop () {}
88

99
function createHashBase (t) { t.base = new HashBase(64) }
@@ -38,7 +38,7 @@ test('HashBase#_transform', function (t) {
3838
t.plan(1)
3939
var err = new Error('hey')
4040
t.base.update = function () { throw err }
41-
t.base._transform(new Buffer(0), 'buffer', function (_err) {
41+
t.base._transform(Buffer.allocUnsafe(0), 'buffer', function (_err) {
4242
t.true(_err === err)
4343
})
4444
t.end()
@@ -52,7 +52,7 @@ test('HashBase#_flush', function (t) {
5252

5353
t.test('should use HashBase#digest', function (t) {
5454
t.plan(2)
55-
var buffer = new Buffer(0)
55+
var buffer = Buffer.allocUnsafe(0)
5656
t.base.push = function (data) { t.true(data === buffer) }
5757
t.base.digest = function () { return buffer }
5858
t.base._flush(function (err) { t.same(err, null) })
@@ -92,13 +92,13 @@ test('HashBase#update', function (t) {
9292
t.test('should use HashBase#_update', function (t) {
9393
t.plan(1)
9494
t.base._update = t.pass
95-
t.base.update(new Buffer(64))
95+
t.base.update(Buffer.allocUnsafe(64))
9696
t.end()
9797
})
9898

9999
t.test('default encoding is utf8', function (t) {
100100
t.plan(1)
101-
var buffer = new Buffer(64)
101+
var buffer = Buffer.allocUnsafe(64)
102102
buffer.fill(0)
103103
utf8buf.copy(buffer)
104104
t.base._update = function () { t.same(this._block, buffer) }
@@ -108,22 +108,21 @@ test('HashBase#update', function (t) {
108108

109109
t.test('decode string with custom encoding', function (t) {
110110
t.plan(1)
111-
var buffer = new Buffer(64)
112-
buffer.fill(0x42)
111+
var buffer = Buffer.allocUnsafe(64).fill(0x42)
113112
t.base._update = function () { t.same(this._block, buffer) }
114113
t.base.update(buffer.toString('hex'), 'hex')
115114
t.end()
116115
})
117116

118117
t.test('data length is more than 2^32 bits', function (t) {
119118
t.base._length = [ Math.pow(2, 32) - 1, 0, 0, 0 ]
120-
t.base.update(new Buffer(1))
119+
t.base.update(Buffer.allocUnsafe(1))
121120
t.same(t.base._length, [ 7, 1, 0, 0 ])
122121
t.end()
123122
})
124123

125124
t.test('should return `this`', function (t) {
126-
t.same(t.base.update(new Buffer(0)), t.base)
125+
t.same(t.base.update(Buffer.allocUnsafe(0)), t.base)
127126
t.end()
128127
})
129128

0 commit comments

Comments
 (0)