[Pkg-javascript-commits] [node-hash-base] 02/06: (Closes #3) remove DEFAULT_ENCODING

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 45dbf3b20b382b8c1c5908aaa82cb59f1dd71bee
Author: Kirill Fomichev <fanatid at ya.ru>
Date:   Wed Apr 6 15:35:20 2016 +0300

    (Closes #3) remove DEFAULT_ENCODING
---
 index.js      | 12 ++----------
 test/index.js | 31 +++++++------------------------
 2 files changed, 9 insertions(+), 34 deletions(-)

diff --git a/index.js b/index.js
index a3b23e6..374f713 100644
--- a/index.js
+++ b/index.js
@@ -9,15 +9,8 @@ function HashBase () {
 
 inherits(HashBase, Transform)
 
-HashBase.DEFAULT_ENCODING = 'buffer'
-
 HashBase.prototype.update = function (data, encoding) {
-  if (!Buffer.isBuffer(data)) {
-    if (encoding === undefined) encoding = HashBase.DEFAULT_ENCODING
-    if (encoding === 'buffer') encoding = 'binary'
-    data = new Buffer(data, encoding)
-  }
-
+  if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding || 'binary')
   this._update(data)
   return this
 }
@@ -27,8 +20,7 @@ HashBase.prototype.digest = function (encoding) {
   this._initialised = false
 
   var digest = this._digest()
-  if (encoding === undefined) encoding = HashBase.DEFAULT_ENCODING
-  if (encoding !== 'buffer') digest = digest.toString(encoding)
+  if (encoding !== undefined) digest = digest.toString(encoding)
   return digest
 }
 
diff --git a/test/index.js b/test/index.js
index 8175cf0..d9969af 100644
--- a/test/index.js
+++ b/test/index.js
@@ -2,13 +2,10 @@
 var test = require('tape').test
 var HashBase = require('../')
 
-var DEFAULT_ENCODING = HashBase.DEFAULT_ENCODING
-
 function beforeEach (t) {
   var _test = t.test
   t.test = function (name, cb) {
     _test(name, function (t) {
-      HashBase.DEFAULT_ENCODING = DEFAULT_ENCODING
       t.base = new HashBase()
       cb(t)
     })
@@ -18,6 +15,12 @@ function beforeEach (t) {
 test('update', function (t) {
   beforeEach(t)
 
+  t.test('should return hash instance', function (t) {
+    t.base._update = function () {}
+    t.same(t.base.update(new Buffer(42)), t.base)
+    t.end()
+  })
+
   t.test('should pass buffer to _update', function (t) {
     t.plan(1)
     var buffer = new Buffer(42)
@@ -26,13 +29,6 @@ test('update', function (t) {
     t.end()
   })
 
-  t.test('should use DEFAULT_ENCODING', function (t) {
-    HashBase.DEFAULT_ENCODING = 'utf-8'
-    t.base._update = function (data) { t.same(data, new Buffer('ZЪ', 'utf-8')) }
-    t.base.update('ZЪ')
-    t.end()
-  })
-
   t.test('should decode string as binary by default', function (t) {
     t.base._update = function (data) { t.same(data, new Buffer('ZЪ', 'binary')) }
     t.base.update('ZЪ')
@@ -45,16 +41,10 @@ test('update', function (t) {
     t.end()
   })
 
-  t.test('should return hash instance', function (t) {
-    t.base._update = function () {}
-    t.same(t.base.update(new Buffer(42)), t.base)
-    t.end()
-  })
-
   t.end()
 })
 
-test('decode', function (t) {
+test('digest', function (t) {
   beforeEach(t)
 
   t.test('should return buffer from _digest by default', function (t) {
@@ -68,13 +58,6 @@ test('decode', function (t) {
     t.end()
   })
 
-  t.test('should use DEFAULT_ENCODING', function (t) {
-    HashBase.DEFAULT_ENCODING = 'utf-8'
-    t.base._digest = function () { return new Buffer('ZЪ', 'utf-8') }
-    t.same(t.base.digest(), 'ZЪ')
-    t.end()
-  })
-
   t.test('should return buffer by default', function (t) {
     t.base._digest = function () { return new Buffer('ZЪ', 'utf-8') }
     t.same(t.base.digest(), new Buffer('ZЪ', 'utf-8'))

-- 
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