[Pkg-javascript-commits] [node-sha.js] 64/237: command to hash a large file

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:02: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 618f16de80ee4b499ab6a493e88845f161dbb0dc
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Mon Dec 30 20:25:15 2013 +0700

    command to hash a large file
---
 bin.js | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/bin.js b/bin.js
new file mode 100755
index 0000000..48c9447
--- /dev/null
+++ b/bin.js
@@ -0,0 +1,40 @@
+#! /usr/bin/env node
+
+var createHash = require('./')
+
+var argv = process.argv.slice(2)
+
+if(/--help|-h/.test(argv[0])) return usage()
+
+function stream (alg, s) {
+  var hash = createHash(alg || 'sha1')
+  s
+  .on('data', function (data) {
+    hash.update(data)
+  })
+  .on('end', function (data) {
+    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))
+
+//  require('fs')
+//    .readFile(filename, function (e, data) {
+//      console.log(createHash(alg).update(data).digest('hex'))
+//    })
+//
+} 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')
+}

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