# SparkMD5
SparkMD5 is a fast md5 implementation of the MD5 algorithm.
This script is based in the JKM md5 library which is the [fastest](http://jsperf.com/md5-shootout/7) algorithm around. This is most suitable for browser usage, because `nodejs` version might be faster.
NOTE: Please disable Firebug while performing the test!
Firebug consumes a lot of memory and CPU and slows the test by a great margin.
**[Demo](http://9px.ir/demo/incremental-md5.html)**
## Install
```sh
npm install --save spark-md5
```
## Improvements over the JKM md5 library
* Strings are converted to utf8, like most server side algorithms
* Fix computation for large amounts of data (overflow)
* Incremental md5 (see bellow)
* Support for array buffers (typed arrays)
* Functionality wrapped in a closure, to avoid global assignments
* Object oriented library
* CommonJS (it can be used in node) and AMD integration
* Code passed through JSHint and JSCS
Incremental md5 performs a lot better for hashing large amounts of data, such as
files. One could read files in chunks, using the FileReader & Blob's, and append
each chunk for md5 hashing while keeping memory usage low. See example below.
## Usage
### Normal usage
```js
var hexHash = SparkMD5.hash('Hi there'); // hex hash
var rawHash = SparkMD5.hash('Hi there', true); // OR raw hash (binary string)
```
### Incremental usage
```js
var spark = new SparkMD5();
spark.append('Hi');
spark.append(' there');
var hexHash = spark.end(); // hex hash
var rawHash = spark.end(true); // OR raw hash (binary string)
```
### Hash a file incrementally
NOTE: If you test the code bellow using the file:// protocol in chrome you must start the browser with -allow-file-access-from-files argument.
Please see: http://code.google.com/p/chromium/issues/detail?id=60889
```js
document.getElementById('file').addEventListener('change', function () {
var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
file = this.files[0],
chunkSize = 2097152, // Read in chunks of 2MB
chunks = Math.ceil(file.size / chunkSize),
currentChunk = 0,
spark = new SparkMD5.ArrayBuffer(),
fileReader = new FileReader();
fileReader.onload = function (e) {
console.log('read chunk nr', currentChunk + 1, 'of', chunks);
spark.append(e.target.result); // Append array buffer
currentChunk++;
if (currentChunk < chunks) {
loadNext();
} else {
console.log('finished loading');
console.info('computed hash', spark.end()); // Compute hash
}
};
fileReader.onerror = function () {
console.warn('oops, something went wrong.');
};
function loadNext() {
var start = currentChunk * chunkSize,
end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
}
loadNext();
});
```
You can see some more examples in the test folder.
## Documentation
### SparkMD5 class
#### SparkMD5#append(str)
Appends a string, encoding it to UTF8 if necessary.
#### SparkMD5#appendBinary(str)
Appends a binary string (e.g.: string returned from the deprecated [readAsBinaryString](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsBinaryString)).
#### SparkMD5#end(raw)
Finishes the computation of the md5, returning the hex result.
If `raw` is true, the result as a binary string will be returned instead.
#### SparkMD5#reset()
Resets the internal state of the computation.
#### SparkMD5#getState()
Returns an object representing the internal computation state.
You can pass this state to setState(). This feature is useful to resume an incremental md5.
#### SparkMD5#setState(state)
Sets the internal computation state. See: getState().
#### SparkMD5#destroy()
Releases memory used by the incremental buffer and other additional resources.
#### SparkMD5.hash(str, raw)
Hashes a string directly, returning the hex result.
If `raw` is true, the result as a binary string will be returned instead.
Note that this function is `static`.
#### SparkMD5.hashBinary(str, raw)
Hashes a binary string directly (e.g.: string returned from the deprecated [readAsBinaryString](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsBinaryString)), returning the hex result.
If `raw` is true, the result as a binary string will be returned instead.
Note that this function is `static`.
### SparkMD5.ArrayBuffer class
#### SparkMD5.ArrayBuffer#append(arr)
Appends an array buffer.
#### SparkMD5.ArrayBuffer#end(raw)
Finishes the computation of the md5, returning the hex result.
If `raw` is true, the result as a binary string will be returned instead.
#### SparkMD5.ArrayBuffer#reset()
Resets the internal state of the computation.
#### SparkMD5.ArrayBuffer#destroy()
Releases memory used by the incremental buffer and other additional resources.
#### SparkMD5.ArrayBuffer#getState()
Returns an object representing the internal computation state.
You can pass this state to setState(). This feature is useful to resume an incremental md5.
#### SparkMD5.ArrayBuffer#setState(state)
Sets the internal computation state. See: getState().
#### SparkMD5.ArrayBuffer.hash(arr, raw)
Hashes an array buffer directly, returning the hex result.
If `raw` is true, the result as a binary string will be returned instead.
Note that this function is `static`.
## License
The project is double licensed, being [WTF2](./LICENSE) the master license and [MIT](./LICENSE2) the alternative license.
The reason to have two licenses is that some entities refuse to use the master license (WTF2) due to
bad language. If that's also your case, you can choose the alternative license.
## Credits
[Joseph Myers](http://www.myersdaily.org/joseph/javascript/md5-text.html)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
MxsDoc是基于Web的文件管理系统,支持权限管理、历史版本管理、Office编辑、Office预览、在线解压缩、文件分享、文件加密、远程存储、跨仓库推送、跨服务器推送、秒传、断点续传、智能搜索、文件备注、本地自动备份、异地自动备份、一键迁移。 1. 开源 Gitee: https://gitee.com/RainyGao/DocSys Github: https://github.com/RainyGao-GitHub/DocSys 2. 多仓库支持 支持定义各自的文件存储、版本管理、权限管理规则 3. 存储安全 本地化文件存储方案,避免系统意外损坏对仓库文件的影响 3. 历史版本 采用目前最流行的SVN和GIT版本仓库 5. 在线编辑 支持各种文本文件在线编辑,支持Office文件协同编辑,无任何外部依赖(无需安装和部署其他Office编辑软件或系统) 6. 文件分享 支持文件和目录分享,支持访问权限设置、密码访问控制 7. 全文搜索 支持文件名、文件备注、文件内容搜索,让文件查找更加方便快捷 8. 后台管理 支持用户管理、用户组管理、仓库管理、系统管理
资源详情
资源评论
资源推荐
收起资源包目录
docsys-win-2.02.31.zip(MxsDoc 专业版 / 企业版) (27582个子文件)
aria_log.00000001 16KB
jmxremote.access 4KB
manifest.appcache 1KB
aria_log_control 52B
AUTHORS 6KB
.babelrc 92B
catalina.bat 13KB
service.bat 6KB
tool-wrapper.bat 4KB
setclasspath.bat 3KB
digest.bat 2KB
configtest.bat 2KB
version.bat 2KB
startup.bat 2KB
shutdown.bat 2KB
InstallAndRunService.bat 2KB
documentserver-generate-allfonts.bat 1KB
mysql_start.bat 1KB
run.bat 1KB
resetroot.bat 1KB
startWithLog.bat 971B
install-components.bat 946B
ctl.bat 810B
start.bat 808B
restart-rabbit.bat 735B
template-ctl.bat 596B
stop.bat 358B
documentserver-log-rotate.bat 335B
InstallNodeJSDebugModule.bat 299B
restart.bat 274B
documentserver-prepare4shutdown.bat 193B
mysql_stop.bat 157B
StartNodeInspector.bat 44B
UniCNS-UTF8-H.bcmap 52KB
UniCNS-UTF32-H.bcmap 51KB
UniCNS-UTF16-H.bcmap 49KB
UniCNS-UCS2-H.bcmap 47KB
UniGB-UTF8-H.bcmap 46KB
UniGB-UTF32-H.bcmap 45KB
UniGB-UTF16-H.bcmap 43KB
UniGB-UCS2-H.bcmap 42KB
UniJIS2004-UTF8-H.bcmap 41KB
UniJIS-UTF8-H.bcmap 41KB
Adobe-CNS1-UCS2.bcmap 40KB
Adobe-Japan1-UCS2.bcmap 40KB
UniJIS2004-UTF32-H.bcmap 40KB
UniJISX02132004-UTF32-H.bcmap 40KB
UniJIS-UTF32-H.bcmap 40KB
UniJISX0213-UTF32-H.bcmap 40KB
UniJIS2004-UTF16-H.bcmap 39KB
UniJIS-UTF16-H.bcmap 39KB
Adobe-GB1-UCS2.bcmap 33KB
UniKS-UTF8-H.bcmap 27KB
UniKS-UTF32-H.bcmap 26KB
UniKS-UTF16-H.bcmap 26KB
UniKS-UCS2-H.bcmap 25KB
UniJIS-UCS2-H.bcmap 25KB
Adobe-Korea1-UCS2.bcmap 23KB
GBK2K-H.bcmap 19KB
KSC-Johab-H.bcmap 16KB
GBK-EUC-H.bcmap 14KB
GBKp-EUC-H.bcmap 14KB
GBTpc-EUC-H.bcmap 7KB
GBT-EUC-H.bcmap 7KB
GBT-H.bcmap 7KB
HKscs-B5-H.bcmap 4KB
ETHK-B5-H.bcmap 4KB
KSCms-UHC-HW-H.bcmap 3KB
KSCms-UHC-H.bcmap 3KB
NWP-H.bcmap 3KB
HKdla-B5-H.bcmap 3KB
78ms-RKSJ-H.bcmap 3KB
Ext-RKSJ-H.bcmap 2KB
Ext-H.bcmap 2KB
Add-H.bcmap 2KB
HKdlb-B5-H.bcmap 2KB
Add-RKSJ-H.bcmap 2KB
78-EUC-H.bcmap 2KB
78-RKSJ-H.bcmap 2KB
78-H.bcmap 2KB
HKgccs-B5-H.bcmap 2KB
HKm471-B5-H.bcmap 2KB
KSCpc-EUC-H.bcmap 2KB
CNS-EUC-V.bcmap 2KB
KSC-EUC-H.bcmap 2KB
KSC-H.bcmap 2KB
CNS-EUC-H.bcmap 2KB
HKm314-B5-H.bcmap 2KB
ETen-B5-H.bcmap 1KB
B5pc-H.bcmap 1KB
B5-H.bcmap 1KB
90pv-RKSJ-H.bcmap 982B
83pv-RKSJ-H.bcmap 905B
UniJISPro-UTF8-V.bcmap 726B
90ms-RKSJ-H.bcmap 721B
90msp-RKSJ-H.bcmap 715B
CNS1-H.bcmap 706B
UniJISPro-UCS2-HW-V.bcmap 705B
UniJISPro-UCS2-V.bcmap 689B
UniJISX02132004-UTF32-V.bcmap 688B
共 27582 条
- 1
- 2
- 3
- 4
- 5
- 6
- 276
RainyFree
- 粉丝: 70
- 资源: 69
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0