-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.js
36 lines (33 loc) · 1.1 KB
/
verify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const fs = require('fs');
const crypto = require('crypto');
const yr = require('./lib/yr');
const Metadata = yr.Metadata;
const metadata = new Metadata();
(async function(){
await metadata.forEach({progress: true, cpus:2}, image => {
return new Promise(resolve => {
const hash = crypto.createHash('sha1');
const stream = fs.createReadStream(image.sourcePath());
stream.on('data', d => hash.update(d));
stream.on('error', err => {
if (err.code !== 'ENOENT') {
console.error(image.sourcePath(), "# error", err);
} else {
console.log(image.sourcePath(), "# missing");
}
resolve();
});
stream.on('end', () => {
const sha1 = hash.digest('hex');
if (sha1 != image.data.sha1) {
console.log(image.sourcePath(), "# invalid");
}
resolve();
});
});
});
})()
.catch(err => {
console.error((err && err.stack) || err);
});