mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 18:23:35 +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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue