|
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 | + const crcCalculator = require('crc'); |
13 | 13 |
|
14 | | - const fileHash = (filePath, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160, crc32) => { |
| 14 | + const fileHash = ( |
| 15 | + filePath, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160, |
| 16 | + crc1, crc8, crc16, crc24, crc32, |
| 17 | + ) => { |
15 | 18 | return new Promise((resolve, reject) => { |
16 | 19 | let MD4, |
17 | 20 | MD5, |
|
21 | 24 | SHA384, |
22 | 25 | SHA512, |
23 | 26 | RIPEMD160, |
24 | | - crc32Checksum; |
| 27 | + crc1Checksum, |
| 28 | + crc8Checksum, |
| 29 | + crc16Checksum, |
| 30 | + crc24Checksum, |
| 31 | + crc32Checksum; |
25 | 32 |
|
26 | 33 | if (md4) MD4 = crypto.createHash('md4'); |
27 | 34 | if (md5) MD5 = crypto.createHash('md5'); |
|
32 | 39 | if (sha512) SHA512 = crypto.createHash('sha512'); |
33 | 40 | if (ripemd160) RIPEMD160 = crypto.createHash('ripemd160'); |
34 | 41 |
|
35 | | - |
36 | 42 | try { |
37 | 43 | const s = fs.createReadStream(filePath.toString()); |
38 | 44 |
|
|
45 | 51 | if (sha384) SHA384.update(data); |
46 | 52 | if (sha512) SHA512.update(data); |
47 | 53 | if (ripemd160) RIPEMD160.update(data); |
48 | | - if (crc32) crc32Checksum = crc32Calculator(data, crc32Checksum); |
| 54 | + if (crc1) crc1Checksum = crcCalculator.crc1(data, crc1Checksum); |
| 55 | + if (crc8) crc8Checksum = crcCalculator.crc8(data, crc8Checksum); |
| 56 | + if (crc16) crc16Checksum = crcCalculator.crc16(data, crc16Checksum); |
| 57 | + if (crc24) crc24Checksum = crcCalculator.crc24(data, crc24Checksum); |
| 58 | + if (crc32) crc32Checksum = crcCalculator.crc32(data, crc32Checksum); |
49 | 59 | }); |
50 | 60 |
|
51 | 61 | s.on('end', () => { |
|
107 | 117 | .toString() |
108 | 118 | }); |
109 | 119 | } |
| 120 | + if (crc1) { |
| 121 | + newHashes.push({ |
| 122 | + type: 'CRC1', |
| 123 | + hash: crc1Checksum.toString(16), |
| 124 | + }); |
| 125 | + } |
| 126 | + if (crc8) { |
| 127 | + newHashes.push({ |
| 128 | + type: 'CRC8', |
| 129 | + hash: crc8Checksum.toString(16), |
| 130 | + }); |
| 131 | + } |
| 132 | + if (crc16) { |
| 133 | + newHashes.push({ |
| 134 | + type: 'CRC16', |
| 135 | + hash: crc16Checksum.toString(16), |
| 136 | + }); |
| 137 | + } |
| 138 | + if (crc24) { |
| 139 | + newHashes.push({ |
| 140 | + type: 'CRC24', |
| 141 | + hash: crc24Checksum.toString(16), |
| 142 | + }); |
| 143 | + } |
110 | 144 | if (crc32) { |
111 | 145 | newHashes.push({ |
112 | 146 | type: 'CRC32', |
|
115 | 149 | } |
116 | 150 |
|
117 | 151 | if (newHashes.length === 0) newHashes = null; |
118 | | - |
119 | 152 | return resolve(newHashes); |
120 | 153 | }); |
121 | 154 |
|
122 | 155 | s.on('error', error => { |
123 | | - |
124 | 156 | return reject(error); |
125 | 157 | }); |
126 | 158 | } catch (error) { |
|
130 | 162 | } |
131 | 163 |
|
132 | 164 | ipcRenderer.on("calculate-file-hash", (e, data) => { |
133 | | - fileHash(data.filePath, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160, data.crc32) |
| 165 | + fileHash( |
| 166 | + data.filePath, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, |
| 167 | + data.ripemd160, data.crc1, data.crc8, data.crc16, data.crc24, data.crc32, |
| 168 | + ) |
134 | 169 | .then(data => { |
135 | 170 | ipcRenderer.send("file-hash-calculated", data); |
136 | 171 | }) |
|
0 commit comments