[Pkg-javascript-commits] [node-sha.js] 84/237: support binary encoding

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:03:38 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 7b0cae71407ec363dc0150c1676fcd0a96a7ea48
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Mon Jan 6 16:23:30 2014 +0700

    support binary encoding
---
 util.js | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/util.js b/util.js
index 6499276..be088ba 100644
--- a/util.js
+++ b/util.js
@@ -20,7 +20,7 @@ var bopsToString = require('bops/typedarray/to')
 
 function write (buffer, string, enc, start, from, to, LE) {
   var l = (to - from)
-  if(enc === 'ascii') {
+  if(enc === 'ascii' || enc === 'binary') {
     for( var i = 0; i < l; i++) {
       buffer[start + i] = string.charCodeAt(i + from)
     }
@@ -54,6 +54,17 @@ function toHex (buf) {
   return s
 }
 
+function toBinary (buf) {
+  var s = ''
+  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 += String.fromCharCode(char)
+  }
+  return s
+}
+
 //always fill to the end!
 function zeroFill(buf, from) {
   for(var i = from; i < buf.byteLength; i++)
@@ -64,5 +75,7 @@ function toString(buf, enc) {
   if(null == enc) return buf
   if('hex' == enc)
     return toHex(buf)
+  if('binary' == enc)
+    return toBinary(buf)
   return bopsToString(buf, enc)
 }

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