[Pkg-javascript-commits] [node-sha.js] 198/237: bin: adhere to standard

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:03:59 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 d1a23ab987eed4a6b940161693a805fa67c6e16d
Author: Daniel Cousens <github at dcousens.com>
Date:   Sat May 30 12:50:09 2015 +1000

    bin: adhere to standard
---
 bin.js | 44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/bin.js b/bin.js
index ef105f6..0a4e95b 100755
--- a/bin.js
+++ b/bin.js
@@ -1,37 +1,43 @@
 #! /usr/bin/env node
 
 var createHash = require('./browserify')
-
 var argv = process.argv.slice(2)
 
-if(/--help|-h/.test(argv[0])) return usage()
-
-function stream (alg, s) {
+function pipe (algorithm, s) {
   var start = Date.now()
-  var hash = createHash(alg || 'sha1')
-  s
-  .on('data', function (data) {
+  var hash = createHash(algorithm || 'sha1')
+
+  s.on('data', function (data) {
     hash.update(data)
   })
-  .on('end', function (data) {
-    if(process.env.DEBUG)
+
+  s.on('end', function () {
+    if (process.env.DEBUG) {
       return console.log(hash.digest('hex'), Date.now() - start)
+    }
+
     console.log(hash.digest('hex'))
   })
 }
- 
-if(!process.stdin.isTTY) {
-  stream(argv[0], process.stdin)
-} else if (argv.length) {
-  var filename = argv.pop()
-  var alg = argv.pop()
-  stream(alg, require('fs').createReadStream(filename))
-} else {
-  usage()
-}
 
 function usage () {
   console.error('sha.js [algorithm=sha1] [filename] # hash filename with algorithm')
   console.error('input | sha.js [algorithm=sha1]    # hash stdin with algorithm')
   console.error('sha.js --help                      # display this message')
 }
+
+if (!process.stdin.isTTY) {
+  pipe(argv[0], process.stdin)
+
+} else if (argv.length) {
+  if (/--help|-h/.test(argv[0])) {
+    usage()
+
+  } else {
+    var filename = argv.pop()
+    var algorithm = argv.pop()
+    pipe(algorithm, require('fs').createReadStream(filename))
+  }
+} else {
+  usage()
+}

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