mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(hash) change structure
This commit is contained in:
parent
62546f1eae
commit
2cea2c70bc
2 changed files with 26 additions and 29 deletions
|
|
@ -2,37 +2,35 @@
|
|||
'use strict';
|
||||
|
||||
var util = require('util'),
|
||||
crypto = require('crypto'),
|
||||
Writable = require('stream').Writable;
|
||||
|
||||
util.inherits(HashProto, Writable);
|
||||
|
||||
object.create = new HashProto().create;
|
||||
|
||||
function HashProto() {
|
||||
var shasum,
|
||||
crypto = require('crypto');
|
||||
object.create = function() {
|
||||
var ret;
|
||||
|
||||
this.create = function() {
|
||||
var ws = new Writable();
|
||||
|
||||
ws._write = write;
|
||||
ws.get = get;
|
||||
|
||||
shasum = crypto.createHash('sha1');
|
||||
|
||||
return ws;
|
||||
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();
|
||||
};
|
||||
|
||||
function get() {
|
||||
var hex = shasum.digest('hex');
|
||||
this.get = function() {
|
||||
var hex = sha.digest('hex');
|
||||
|
||||
return hex;
|
||||
}
|
||||
|
||||
function write (chunk, enc, next) {
|
||||
shasum.update(chunk);
|
||||
next();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
})(this);
|
||||
|
|
|
|||
|
|
@ -117,13 +117,13 @@
|
|||
});
|
||||
});
|
||||
else if (Util.strCmp(lQuery, 'hash')) {
|
||||
if (!Hash) {
|
||||
hash = Hash.create();
|
||||
|
||||
if (!hash) {
|
||||
lMsg = 'not suported, try update node';
|
||||
lMsg = CloudFunc.formatMsg('hash', lMsg, 'error');
|
||||
sendError(p, lMsg);
|
||||
} else {
|
||||
hash = Hash.create();
|
||||
|
||||
} else
|
||||
pipe.create({
|
||||
from : p.name,
|
||||
write : hash,
|
||||
|
|
@ -134,7 +134,6 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else
|
||||
fs.stat(p.name, function(pError, pStat) {
|
||||
checkSendError(pError, p, function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue