1 | # Introduction
|
2 |
|
3 | A MD5 implementation for TypeScript
|
4 |
|
5 | * Can handle Unicode strings
|
6 | * Supports incremental hashing
|
7 | * Works with Files and Blobs
|
8 |
|
9 | This 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 |
|
18 | Based 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 |
|
29 | Install the node module with `npm install ts-md5`
|
30 |
|
31 | ### Basic Hashing
|
32 |
|
33 | 1. Import the class
|
34 | * `import {Md5} from 'ts-md5';`
|
35 | 2. 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 |
|
41 | For more complex uses:
|
42 |
|
43 | ```typescript
|
44 |
|
45 | md5 = new Md5();
|
46 |
|
47 | // Append incrementally your file or other input
|
48 | // Methods are chainable
|
49 | md5.appendStr('somestring')
|
50 | .appendAsciiStr('a different string')
|
51 | .appendByteArray(blob);
|
52 |
|
53 | // Generate the MD5 hex string
|
54 | md5.end();
|
55 |
|
56 | ```
|
57 |
|
58 |
|
59 | ### Hashing a File
|
60 |
|
61 | NOTE:: 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
|
62 | It should always remain as a seperate file.
|
63 |
|
64 | ```typescript
|
65 |
|
66 | import {ParallelHasher} from 'ts-md5';
|
67 |
|
68 | let hasher = new ParallelHasher('/path/to/ts-md5/dist/md5_worker.js');
|
69 | hasher.hash(fileBlob).then(function(result) {
|
70 | console.log('md5 of fileBlob is', result);
|
71 | });
|
72 |
|
73 | ```
|
74 |
|
75 |
|
76 | ## Building from src
|
77 |
|
78 | The project is written in typescript and transpiled into ES5.
|
79 |
|
80 | 1. Install TypeScript: `npm install -g typescript` (if you haven't already)
|
81 | 2. Configure compile options in `tsconfig.json`
|
82 | 3. Perform build using: `tsc`
|
83 |
|
84 | You can find more information here: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json
|
85 |
|
86 | ## Scripts
|
87 |
|
88 | 1. Build Script: `npm run build`
|
89 | 2. Test Script: `npm run test`
|
90 |
|
91 |
|
92 | ## Publishing
|
93 |
|
94 | 1. Sign up to https://www.npmjs.com/
|
95 | 2. Configure `package.json` https://docs.npmjs.com/files/package.json
|
96 | 3. run `npm publish` https://docs.npmjs.com/cli/publish
|
97 |
|
98 |
|
99 | # License
|
100 |
|
101 | MIT
|