Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 368x 368x 1x 1x 1x 1x 1x 1x 1x 1x 368x 368x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 17x 17x 17x 17x 17x 90x 482x 482x 482x 8x 8x 482x 73x 482x 396x 396x 482x 90x 17x 17x 17x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 358x 358x 358x 358x 358x 13x 13x | "use strict";
/**
* Hashing helpers used to identify preparation inputs.
*
* @module util/hash
*/
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
/**
* SHA-256 of a buffer or string, hex encoded.
*
* @param {Buffer|String} data - data to hash
* @return {String} hex digest
*/
export function sha256(data: string | Buffer): string {
return crypto.createHash("sha256").update(data).digest("hex");
}
/**
* SHA-256 of a file's content.
*
* @param {String} file - file path
* @return {String} hex digest
*/
export function sha256File(file: string): string {
return sha256(fs.readFileSync(file));
}
/**
* List files under a directory recursively, sorted, as relative POSIX paths.
* Symbolic links are not followed.
*
* @param {String} dir - directory
* @param {Function} [filter] - returns false to skip a relative path
* @return {Array} relative file paths
*/
export function listFiles(
dir: string,
filter: (rel: string) => boolean = () => true,
): string[] {
const out: string[] = [];
const walk = (current: string) => {
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
const abs = path.join(current, entry.name);
const rel = path.relative(dir, abs).split(path.sep).join("/");
if (!filter(rel)) {
continue;
}
if (entry.isDirectory()) {
walk(abs);
} else if (entry.isFile()) {
out.push(rel);
}
}
};
walk(dir);
return out.sort();
}
/**
* Deterministic hash of a directory tree (relative paths and contents).
*
* @param {String} dir - directory
* @param {Function} [filter] - returns false to skip a relative path
* @return {String} hex digest
*/
export function sha256Tree(
dir: string,
filter?: (rel: string) => boolean,
): string {
const h = crypto.createHash("sha256");
for (const rel of listFiles(dir, filter)) {
h.update(rel);
h.update("\0");
h.update(sha256File(path.join(dir, rel)));
h.update("\n");
}
return h.digest("hex");
}
|