|
9 | 9 | const ipcRenderer = window.require('electron').ipcRenderer; |
10 | 10 | const fs = window.require('fs'); |
11 | 11 | const crypto = window.require('crypto'); |
| 12 | + const crc32Calculator = require('crc').crc32; |
12 | 13 |
|
13 | | - const fileHash = (filePath, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160) => { |
| 14 | + const fileHash = (filePath, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160, crc32) => { |
14 | 15 | return new Promise((resolve, reject) => { |
15 | 16 | let MD4, |
16 | 17 | MD5, |
|
19 | 20 | SHA256, |
20 | 21 | SHA384, |
21 | 22 | SHA512, |
22 | | - RIPEMD160; |
| 23 | + RIPEMD160, |
| 24 | + crc32Checksum; |
23 | 25 |
|
24 | 26 | if (md4) MD4 = crypto.createHash('md4'); |
25 | 27 | if (md5) MD5 = crypto.createHash('md5'); |
|
30 | 32 | if (sha512) SHA512 = crypto.createHash('sha512'); |
31 | 33 | if (ripemd160) RIPEMD160 = crypto.createHash('ripemd160'); |
32 | 34 |
|
| 35 | + |
33 | 36 | try { |
34 | 37 | const s = fs.createReadStream(filePath.toString()); |
35 | 38 |
|
|
42 | 45 | if (sha384) SHA384.update(data); |
43 | 46 | if (sha512) SHA512.update(data); |
44 | 47 | if (ripemd160) RIPEMD160.update(data); |
| 48 | + if (crc32) crc32Checksum = crc32Calculator(data, crc32Checksum); |
45 | 49 | }); |
46 | 50 |
|
47 | 51 | s.on('end', () => { |
|
103 | 107 | .toString() |
104 | 108 | }); |
105 | 109 | } |
| 110 | + if (crc32) { |
| 111 | + newHashes.push({ |
| 112 | + type: 'CRC32', |
| 113 | + hash: crc32Checksum.toString(16), |
| 114 | + }); |
| 115 | + } |
106 | 116 |
|
107 | 117 | if (newHashes.length === 0) newHashes = null; |
108 | 118 |
|
|
120 | 130 | } |
121 | 131 |
|
122 | 132 | ipcRenderer.on("calculate-file-hash", (e, data) => { |
123 | | - fileHash(data.filePath, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160) |
| 133 | + fileHash(data.filePath, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160, data.crc32) |
124 | 134 | .then(data => { |
125 | 135 | ipcRenderer.send("file-hash-calculated", data); |
126 | 136 | }) |
|
0 commit comments