openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
35 lines (34 loc) • 1.09 kB
JavaScript
import { closeSync, createReadStream, openSync } from "node:fs";
import { createHash, hash } from "node:crypto";
import { sha256FileSync } from "@openclaw/fs-safe/durability";
//#region src/infra/crypto-digest.ts
function sha256Base64Url(e) {
return hash("sha256", e, "base64url");
}
function sha256Base64UrlPrefix(e, t) {
return sha256Base64Url(e).slice(0, t);
}
/** Matches the streaming helper's symlink-following path contract. */
function sha256FileSync$1(e) {
const t = openSync(e, "r");
try {
return sha256FileSync(t).digest;
} finally {
closeSync(t);
}
}
/** Streams a file, optionally stopping at an inclusive byte offset. */
async function sha256File$1(e, t) {
const n = createHash("sha256");
try {
for await (const r of createReadStream(e, {
end: t,
highWaterMark: 262144
})) n.update(r);
} catch (t) {
throw new Error(`Failed to hash file ${e}: ${t instanceof Error ? t.message : String(t)}`, { cause: t });
}
return n.digest("hex");
}
//#endregion
export { sha256FileSync$1 as i, sha256Base64UrlPrefix as n, sha256File$1 as r, sha256Base64Url as t };