feature(hash) hash -> ashify

This commit is contained in:
coderaiser 2014-12-09 03:50:29 -05:00
parent 35ad8de19d
commit 40ded6b424
3 changed files with 12 additions and 53 deletions

View file

@ -5,13 +5,14 @@
DIR_LIB = DIR_SERVER + '../',
path = require('path'),
fs = require('fs'),
Util = require(DIR_LIB + 'util'),
CloudFunc = require(DIR_LIB + 'cloudfunc'),
patch = require(DIR_SERVER + 'patch'),
hash = require(DIR_SERVER + 'hash'),
ashify = require('ashify'),
mellow = require('mellow'),
files = require('files-io');
mellow = require('mellow');
module.exports = function(sock) {
Util.check(arguments, ['socket']);
@ -48,19 +49,12 @@
};
function getHash(name, callback) {
var error, hashStream = hash();
if (!hashStream) {
error = 'hash: not suported, try update node';
callback(Error(error));
} else
files.pipe(name, hashStream, function (error) {
var hex;
if (!error)
hex = hashStream.get();
callback(error, hex);
});
var stream = fs.createReadStream(name),
options = {
algorithm: 'sha1',
encoding: 'hex'
};
ashify(stream, options, callback);
}
})();

View file

@ -1,36 +0,0 @@
(function () {
'use strict';
var util = require('util'),
crypto = require('crypto'),
Writable = require('stream').Writable;
module.exports = function() {
var ret;
if (Writable) {
util.inherits(WS, Writable);
ret = new WS();
}
return ret;
};
function WS(opt) {
var sha = crypto.createHash('sha1');
Writable.call(this, opt);
this._write = function(chunk, enc, next) {
sha.update(chunk);
next();
};
this.get = function() {
var hex = sha.digest('hex');
return hex;
};
}
})();

View file

@ -25,6 +25,7 @@
},
"subdomain": "cloudcmd",
"dependencies": {
"ashify": "~1.0.0",
"checkup": "~1.0.2",
"console-io": "~1.11.0",
"execon": "~1.0.1",