Update CDN Hosts

This commit is contained in:
SukkaW
2026-08-01 19:29:12 +08:00
parent 3e9f630c79
commit 7b29116f4e
2 changed files with 19 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
import { Buffer } from 'node:buffer';
import { createHash } from 'node:crypto';
import fs from 'node:fs';
import fsp from 'node:fs/promises';
/**
@@ -64,6 +65,21 @@ export async function extractContentHashFromFile(filePath: string): Promise<stri
return extractContentHash(await readFileHead(filePath));
}
/** Synchronous variant of {@link extractContentHashFromFile}, for worker threads where blocking is fine */
export function extractContentHashFromFileSync(filePath: string): string | null {
let fd: number | null = null;
try {
fd = fs.openSync(filePath, 'r');
const buf = Buffer.allocUnsafe(FILE_HEAD_CHUNK_SIZE);
const bytesRead = fs.readSync(fd, buf, 0, FILE_HEAD_CHUNK_SIZE, 0);
return extractContentHash(buf.toString('utf8', 0, bytesRead));
} finally {
if (fd !== null) {
fs.closeSync(fd);
}
}
}
function extractContentHash(fileHead: string): string | null {
const markerIndex = fileHead.indexOf(CONTENT_HASH_MARKER_START);
if (markerIndex === -1) {