mirror of
https://github.com/morluto/rea.git
synced 2026-11-14 18:52:48 +00:00
Use one bounded positional byte comparator for client configuration and skill publication readback. Keep pathname identity, rollback, mode restoration, cleanup and retry authority in the existing publication owners. Preserve short-read progress, EOF, empty-file equality and original I/O errors. Extend existing byte-exact skill recovery coverage to empty originals. Validation: client configuration transaction, skill publication recovery and process-global rollback suites passed; static, docs and discovery checks passed.
28 lines
846 B
TypeScript
28 lines
846 B
TypeScript
import type { FileHandle } from "node:fs/promises";
|
|
|
|
/** Compare descriptor bytes without taking ownership or validating pathname identity. */
|
|
export const fileHandleMatchesBytes = async (
|
|
handle: Pick<FileHandle, "stat" | "read">,
|
|
expected: Buffer,
|
|
): Promise<boolean> => {
|
|
if ((await handle.stat()).size !== expected.length) return false;
|
|
const chunk = Buffer.allocUnsafe(Math.min(64 * 1024, expected.length));
|
|
for (let position = 0; position < expected.length;) {
|
|
const { bytesRead } = await handle.read(
|
|
chunk,
|
|
0,
|
|
Math.min(chunk.length, expected.length - position),
|
|
position,
|
|
);
|
|
if (
|
|
bytesRead === 0 ||
|
|
!chunk
|
|
.subarray(0, bytesRead)
|
|
.equals(expected.subarray(position, position + bytesRead))
|
|
)
|
|
return false;
|
|
position += bytesRead;
|
|
}
|
|
return true;
|
|
};
|