refactor(hash) change structure

This commit is contained in:
coderaiser 2013-11-19 09:33:51 +00:00
parent 62546f1eae
commit 2cea2c70bc
2 changed files with 26 additions and 29 deletions

View file

@ -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);