[Pkg-javascript-commits] [node-hash-base] 08/13: Only Node v4 or greater
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 12 22:00:54 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch upstream
in repository node-hash-base.
commit 8e24ac9258a1c9294960ee24820eed7494c38e10
Author: Kirill Fomichev <fanatid at ya.ru>
Date: Wed Nov 2 13:04:53 2016 +0300
Only Node v4 or greater
---
.travis.yml | 3 ---
index.js | 4 ++--
package.json | 3 +++
test/index.js | 17 ++++++++---------
4 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index f7227d0..b07fd55 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,6 @@
sudo: false
language: node_js
node_js:
- - "0.10"
- - "0.11"
- - "0.12"
- "4"
- "5"
- "6"
diff --git a/index.js b/index.js
index e455590..34903b7 100644
--- a/index.js
+++ b/index.js
@@ -11,7 +11,7 @@ function throwIfNotStringOrBuffer (val, prefix) {
function HashBase (blockSize) {
Transform.call(this)
- this._block = new Buffer(blockSize)
+ this._block = Buffer.allocUnsafe(blockSize)
this._blockSize = blockSize
this._blockOffset = 0
this._length = [0, 0, 0, 0]
@@ -46,7 +46,7 @@ HashBase.prototype._flush = function (callback) {
HashBase.prototype.update = function (data, encoding) {
throwIfNotStringOrBuffer(data, 'Data')
if (this._finalized) throw new Error('Digest already called')
- if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding)
+ if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)
// consume data
var block = this._block
diff --git a/package.json b/package.json
index cd076f3..ae7ad71 100644
--- a/package.json
+++ b/package.json
@@ -33,5 +33,8 @@
"nyc": "^8.3.2",
"standard": "*",
"tape": "^4.2.0"
+ },
+ "engines": {
+ "node": ">=4"
}
}
diff --git a/test/index.js b/test/index.js
index 28a2a14..95fdab2 100644
--- a/test/index.js
+++ b/test/index.js
@@ -3,7 +3,7 @@ var test = require('tape')
var HashBase = require('../')
var utf8text = 'УТФ-8 text'
-var utf8buf = new Buffer(utf8text, 'utf8')
+var utf8buf = Buffer.from(utf8text, 'utf8')
function noop () {}
function createHashBase (t) { t.base = new HashBase(64) }
@@ -38,7 +38,7 @@ test('HashBase#_transform', function (t) {
t.plan(1)
var err = new Error('hey')
t.base.update = function () { throw err }
- t.base._transform(new Buffer(0), 'buffer', function (_err) {
+ t.base._transform(Buffer.allocUnsafe(0), 'buffer', function (_err) {
t.true(_err === err)
})
t.end()
@@ -52,7 +52,7 @@ test('HashBase#_flush', function (t) {
t.test('should use HashBase#digest', function (t) {
t.plan(2)
- var buffer = new Buffer(0)
+ var buffer = Buffer.allocUnsafe(0)
t.base.push = function (data) { t.true(data === buffer) }
t.base.digest = function () { return buffer }
t.base._flush(function (err) { t.same(err, null) })
@@ -92,13 +92,13 @@ test('HashBase#update', function (t) {
t.test('should use HashBase#_update', function (t) {
t.plan(1)
t.base._update = t.pass
- t.base.update(new Buffer(64))
+ t.base.update(Buffer.allocUnsafe(64))
t.end()
})
t.test('default encoding is utf8', function (t) {
t.plan(1)
- var buffer = new Buffer(64)
+ var buffer = Buffer.allocUnsafe(64)
buffer.fill(0)
utf8buf.copy(buffer)
t.base._update = function () { t.same(this._block, buffer) }
@@ -108,8 +108,7 @@ test('HashBase#update', function (t) {
t.test('decode string with custom encoding', function (t) {
t.plan(1)
- var buffer = new Buffer(64)
- buffer.fill(0x42)
+ var buffer = Buffer.allocUnsafe(64).fill(0x42)
t.base._update = function () { t.same(this._block, buffer) }
t.base.update(buffer.toString('hex'), 'hex')
t.end()
@@ -117,13 +116,13 @@ test('HashBase#update', function (t) {
t.test('data length is more than 2^32 bits', function (t) {
t.base._length = [ Math.pow(2, 32) - 1, 0, 0, 0 ]
- t.base.update(new Buffer(1))
+ t.base.update(Buffer.allocUnsafe(1))
t.same(t.base._length, [ 7, 1, 0, 0 ])
t.end()
})
t.test('should return `this`', function (t) {
- t.same(t.base.update(new Buffer(0)), t.base)
+ t.same(t.base.update(Buffer.allocUnsafe(0)), t.base)
t.end()
})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-hash-base.git
More information about the Pkg-javascript-commits
mailing list