UNPKG

2.33 kBMarkdownView Raw
1# Introduction
2
3A MD5 implementation for TypeScript
4
5* Can handle Unicode strings
6* Supports incremental hashing
7* Works with Files and Blobs
8
9This library also includes tools for:
10
11* Hashing a file or blob
12* A webworker for performing hashing
13* A webworker handler for requesting files or blobs to be hashed
14 * promise based
15 * files or blobs are queued for processing on the webworker
16
17
18Based on work by
19
20* Joseph Myers: http://www.myersdaily.org/joseph/javascript/md5-text.html
21* André Cruz: https://github.com/satazor/SparkMD5
22* Raymond Hill: https://github.com/gorhill/yamd5.js
23
24
25## Usage
26
27### Install
28
29Install the node module with `npm install ts-md5`
30
31### Basic Hashing
32
331. Import the class
34 * `import {Md5} from 'ts-md5';`
352. Hash some things
36 * `Md5.hashStr('blah blah blah')` => hex:string
37 * `Md5.hashStr('blah blah blah', true)` => raw:Int32Array(4)
38 * `Md5.hashAsciiStr('blah blah blah')` => hex:string
39 * `Md5.hashAsciiStr('blah blah blah', true)` => raw:Int32Array(4)
40
41For more complex uses:
42
43```typescript
44
45md5 = new Md5();
46
47// Append incrementally your file or other input
48// Methods are chainable
49md5.appendStr('somestring')
50 .appendAsciiStr('a different string')
51 .appendByteArray(blob);
52
53// Generate the MD5 hex string
54md5.end();
55
56```
57
58
59### Hashing a File
60
61NOTE:: You have to make sure `ts-md5/dist/md5_worker.js` is made available in your build so it can be accessed directly by a browser
62It should always remain as a seperate file.
63
64```typescript
65
66import {ParallelHasher} from 'ts-md5';
67
68let hasher = new ParallelHasher('/path/to/ts-md5/dist/md5_worker.js');
69hasher.hash(fileBlob).then(function(result) {
70 console.log('md5 of fileBlob is', result);
71});
72
73```
74
75
76## Building from src
77
78The project is written in typescript and transpiled into ES5.
79
801. Install TypeScript: `npm install -g typescript` (if you haven't already)
812. Configure compile options in `tsconfig.json`
823. Perform build using: `tsc`
83
84You can find more information here: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json
85
86## Scripts
87
881. Build Script: `npm run build`
892. Test Script: `npm run test`
90
91
92## Publishing
93
941. Sign up to https://www.npmjs.com/
952. Configure `package.json` https://docs.npmjs.com/files/package.json
963. run `npm publish` https://docs.npmjs.com/cli/publish
97
98
99# License
100
101MIT