mirror of
https://github.com/morluto/rea.git
synced 2026-11-24 13:18:39 +00:00
The classification probe already scans every stream for an XML plist prolog while it retains the prefix. Content classification discarded that verdict and scanned the retained prefix again with a fresh probe, so each entry paid for two decodes of its first chunk. Classification evidence now carries the probe's verdict, and the single-buffer `hasXmlPlistSignature` wrapper, which only that second scan used, is removed. The probe also stops once the prolog scanner rejects: fatal-decoder validation and byte accounting cannot change a rejection. Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
28 lines
1000 B
TypeScript
28 lines
1000 B
TypeScript
import { classifyArtifactContent } from "../../src/artifacts/inventory/ArtifactGraphConstruction.js";
|
|
import { createXmlPlistSignatureProbe } from "../../src/domain/apple/appleArchiveFormat.js";
|
|
import { readFatContainerHeader } from "../../src/domain/apple/machoContainer.js";
|
|
import { createAsarHeaderSignatureProbe } from "../../src/resources/index.js";
|
|
|
|
/** Observe a supplied byte prefix before assigning an inventory path role. */
|
|
export const classifyArtifactBytesAtPath = (
|
|
path: string,
|
|
bytes: Buffer,
|
|
fileSize = bytes.length,
|
|
) => {
|
|
const probe = createAsarHeaderSignatureProbe();
|
|
probe.write(bytes);
|
|
const { kind, format } = classifyArtifactContent(
|
|
path,
|
|
{
|
|
prefix: bytes,
|
|
xmlPlistSignature:
|
|
createXmlPlistSignatureProbe().write(bytes) === "matched",
|
|
asarHeader: probe.finish(fileSize),
|
|
fatHeader: readFatContainerHeader(bytes, fileSize),
|
|
fatSliceHeadersByOffset: new Map(),
|
|
},
|
|
fileSize,
|
|
);
|
|
return { kind, format };
|
|
};
|