From 1b47867f9ca2d2bd736efe25ae39dff04c5f0299 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 21 Nov 2013 11:11:26 +0000 Subject: [PATCH] feature(edit) rm client sha --- lib/client/dom.js | 28 ++--- lib/client/edit.js | 27 ++--- lib/sha1/README.md | 60 ---------- lib/sha1/package.json | 22 ---- lib/sha1/rusha.js | 270 ------------------------------------------ 5 files changed, 18 insertions(+), 389 deletions(-) delete mode 100644 lib/sha1/README.md delete mode 100644 lib/sha1/package.json delete mode 100644 lib/sha1/rusha.js diff --git a/lib/client/dom.js b/lib/client/dom.js index 8c878f5e..b67340f2 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1781,30 +1781,24 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; * @param data * @param callback */ - this.saveDataToStorage = function(name, data, hash, callback) { + this.saveDataToStorage = function(name, data, callback) { CloudCmd.getConfig(function(config) { var allowed = config.localStorage, isDir = DOM.isCurrentIsDir(), nameHash = name + '-hash', - nameData = name + '-data', - save = function(hash) { - Storage.set(nameHash, hash); - Storage.set(nameData, data); - }; + nameData = name + '-data'; if (!allowed || isDir) Util.exec(callback); - else { - if (hash) - save(hash); - else - DOM.checkStorageHash(name, function(error, equal, hash) { - if (!error && !equal) - save(hash); - - Util.exec(callback, hash); - }); - } + else + DOM.checkStorageHash(name, function(error, equal, hash) { + if (!error && !equal) { + Storage.set(nameHash, hash); + Storage.set(nameData, data); + } + + Util.exec(callback, hash); + }); }); }; diff --git a/lib/client/edit.js b/lib/client/edit.js index 75640e74..41c9621b 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -12,7 +12,6 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; Value, Edit = this, Diff, - SHA, Ace, Msg, Dialog = DOM.Dialog, @@ -161,20 +160,12 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; } DOM.checkStorageHash(lPath, function(error, equal) { - var ret, - msg = 'File is changed, overwrite?', - saveFunc = function(text) { - var hash = SHA.digest(Value); - onSave(text, hash); - }; - - if (!error && !equal) - ret = Dialog.confirm(msg); - else - DOM.RESTful.save(lPath, lValue, saveFunc, query); + if (!error) { + if (!equal) + query = ''; - if (ret) - DOM.RESTful.save(lPath, lValue, saveFunc); + DOM.RESTful.save(lPath, lValue, onSave, query); + } }); }, function(callback) { @@ -188,16 +179,12 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; function diff(pNewValue, pCallBack) { var libs = [ LIBDIR + 'diff.js', - LIBDIR + 'diff/diff-match-patch.js', - LIBDIR + 'sha1/rusha.js' + LIBDIR + 'diff/diff-match-patch.js' ]; DOM.anyLoadInParallel(libs, function() { var patch; - if (!SHA) - SHA = new Rusha(); - if (!Diff) Diff = new DiffProto(diff_match_patch); @@ -243,7 +230,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; if (!isError) { Edit.showMessage(text); - DOM.saveDataToStorage(path, Value, hash); + DOM.saveDataToStorage(path, Value); } else { ret = Dialog.confirm(text + msg); diff --git a/lib/sha1/README.md b/lib/sha1/README.md deleted file mode 100644 index 6d806560..00000000 --- a/lib/sha1/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# Rusha -*A high-performance pure-javascript SHA1 implementation suitable for large binary data.* - -## Prologue: The Sad State of Javascript SHA1 implementations - -When we started experimenting with alternative upload technologies at [doctape](http://doctape.com) that required creating SHA1 hashes of the data locally on the client, it quickly became obvious that there were no performant pure-js implementations of SHA1 that worked correctly on binary data. - -Jeff Mott's [CryptoJS](http://code.google.com/p/crypto-js/) and Brian Turek's [jsSHA](http://caligatio.github.com/jsSHA/) were both hash functions that worked correctly on ASCII strings of a small size, but didn't scale to large data and/or didn't work correctly with binary data. - -(On a sidenode, as of now Tim Caswell's [Cifre](http://github.com/openpeer/cifre) actually works with large binary data, as opposed to previously statet.) - -By modifying Paul Johnston's [sha1.js](http://pajhome.org.uk/crypt/md5/sha1.html) slightly, it worked correctly on binary data but was unfortunately very slow, especially on V8. So a few days were invested on my side to implement a Johnston-inspired SHA1 hashing function with a heavy focus on performance. - -The result of this process is Rusha, a SHA1 hash function that works flawlessly on large amounts binary data, such as binary strings or ArrayBuffers returned by the HTML5 File API, and leverages the soon-to-be-landed-in-firefox [asm.js](http://asmjs.org/spec/latest/) with whose support its within *half of native speed*! - -## Installing - -### Node.JS - -There is really no point in doing this, since Node.JS already has a wonderful `crypto` module that is leveraging low-level hardware instructions to perform really nice. Your can see the comparison below in the benchmarks. - -Rusha is available on [npm](http://npmjs.org/) via `npm install rusha`. - -If you still want to do this, anyhow, just `require()` the `rusha.js` file, follow the instructions on _Using the Rusha Object_. - -### Browser - -Rusha is available on [bower](http://twitter.github.com/bower/) via `bower install rusha`. - -It is highly recommended to run CPU-intensive tasks in a [Web Worker](http://developer.mozilla.org/en-US/docs/DOM/Using_web_workers). To do so, just start a worker with `var worker = new Worker('rusha.js')` and start sending it jobs. Follow the instructions on _Using the Rusha Worker_. - -If you can't, for any reason, use Web Workers, include the `rusha.js` file in a `