Chore: dispatch write to workers

This commit is contained in:
SukkaW
2026-08-02 00:09:56 +08:00
parent 6d8070d5f3
commit fa9c02d27d
9 changed files with 528 additions and 199 deletions

View File

@@ -1,7 +1,6 @@
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';
/**
@@ -65,21 +64,6 @@ 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) {