[Pkg-javascript-commits] [node-hash-base] 03/06: (#1) rename _initialized to _finalized

Bastien Roucariès rouca at moszumanska.debian.org
Thu May 4 10:21:23 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to annotated tag v2.0.0
in repository node-hash-base.

commit ea3c00fdf768f68313e07f1d93652316f94d9de9
Author: Kirill Fomichev <fanatid at ya.ru>
Date:   Wed Apr 6 15:42:44 2016 +0300

    (#1) rename _initialized to _finalized
---
 index.js      |  7 ++++---
 test/index.js | 12 +++++++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/index.js b/index.js
index 374f713..a73ecc2 100644
--- a/index.js
+++ b/index.js
@@ -4,20 +4,21 @@ var inherits = require('inherits')
 
 function HashBase () {
   Transform.call(this)
-  this._initialised = true
+  this._finalized = false
 }
 
 inherits(HashBase, Transform)
 
 HashBase.prototype.update = function (data, encoding) {
+  if (this._finalized) throw new Error('Digest already called')
   if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding || 'binary')
   this._update(data)
   return this
 }
 
 HashBase.prototype.digest = function (encoding) {
-  if (!this._initialised) throw new Error('Not initialized')
-  this._initialised = false
+  if (this._finalized) throw new Error('Digest already called')
+  this._finalized = true
 
   var digest = this._digest()
   if (encoding !== undefined) digest = digest.toString(encoding)
diff --git a/test/index.js b/test/index.js
index d9969af..cc4e925 100644
--- a/test/index.js
+++ b/test/index.js
@@ -41,6 +41,16 @@ test('update', function (t) {
     t.end()
   })
 
+  t.test('call after digest should throw error', function (t) {
+    t.base._update = function () {}
+    t.base._digest = function () {}
+    t.base.digest()
+    t.throws(function () {
+      t.base.update()
+    }, /^Error: Digest already called$/)
+    t.end()
+  })
+
   t.end()
 })
 
@@ -75,7 +85,7 @@ test('digest', function (t) {
     t.base.digest()
     t.throws(function () {
       t.base.digest()
-    }, /^Error: Not initialized$/)
+    }, /^Error: Digest already called$/)
     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