[Pkg-javascript-commits] [node-sha.js] 31/237: toHex supports strings and buffers

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:02:52 UTC 2017


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

rouca pushed a commit to branch master
in repository node-sha.js.

commit 9e173551bba96b7a6d395311948a4887e1461e5e
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Fri Dec 27 11:38:17 2013 +0700

    toHex supports strings and buffers
---
 util.js | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/util.js b/util.js
index 637a109..0c18fb7 100644
--- a/util.js
+++ b/util.js
@@ -20,7 +20,6 @@ exports.Uint32toHex = Uint32toHex
 //OKAY, I should have benchmarks before I worry about that.
 
 function write (buffer, string, enc, start, from, to, LE) {
-
   var l = (to - from)
   if(enc === 'ascii') {
     for( var i = 0; i < l; i++) {
@@ -41,6 +40,19 @@ function write (buffer, string, enc, start, from, to, LE) {
   else if(enc === 'base64') {
     throw new Error('base64 encoding not yet supported')
   }
+  else
+    throw new Error(enc +' encoding not yet supported')
+}
+
+function toHex (buf) {
+  buf = buf.buffer || buf
+  var l = 'string' === typeof buf ? buf.length : buf.byteLength
+  var s = ''
+  for(var i = 0; i < l; i++) {
+    var char = buf.charCodeAt ? buf.charCodeAt(i) : buf[i]
+    s += ((char>>4).toString(16)) + ((char&0xf).toString(16))
+  }
+  return s
 }
 
 
@@ -72,12 +84,3 @@ function Uint32toHex (n) {
   return s
 }
 
-function toHex (buf) {
-  var s = '', length = buf.byteLength || buf.length
-  for(var i = 0; i < length; i++) {
-    var char = buf.charCodeAt ? buf.charCodeAt(i) : buf[i]
-    s += (char>>4).toString(16) + ((char & 0x0f)).toString(16)
-  }
-  return s
-}
-

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-sha.js.git



More information about the Pkg-javascript-commits mailing list