From 40ded6b42419c2d4920ef44c1a3966669dbb2c5d Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 9 Dec 2014 03:50:29 -0500 Subject: [PATCH] feature(hash) hash -> ashify --- lib/server/edit.js | 28 +++++++++++----------------- lib/server/hash.js | 36 ------------------------------------ package.json | 1 + 3 files changed, 12 insertions(+), 53 deletions(-) delete mode 100644 lib/server/hash.js diff --git a/lib/server/edit.js b/lib/server/edit.js index e00c9614..eda9c635 100644 --- a/lib/server/edit.js +++ b/lib/server/edit.js @@ -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); } })(); diff --git a/lib/server/hash.js b/lib/server/hash.js deleted file mode 100644 index b02d3bb8..00000000 --- a/lib/server/hash.js +++ /dev/null @@ -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; - }; - } - -})(); diff --git a/package.json b/package.json index 8abd9c1a..94d74174 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "subdomain": "cloudcmd", "dependencies": { + "ashify": "~1.0.0", "checkup": "~1.0.2", "console-io": "~1.11.0", "execon": "~1.0.1",