From 422db111855f0e3accd041c33cc342ae4f4d4e7d Mon Sep 17 00:00:00 2001 From: Bonobo Date: Wed, 2 Sep 2026 13:33:49 +0200 Subject: [PATCH] perf(artifacts): decode text once per file --- src/artifacts/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/artifacts/index.ts b/src/artifacts/index.ts index 61be983..5e5b03c 100644 --- a/src/artifacts/index.ts +++ b/src/artifacts/index.ts @@ -58,14 +58,14 @@ export function inventoryArtifacts( } catch { continue; // unreadable — skip, don't crash } + const text = decodeLossy(raw); if (!matched) { // Never drop: a file without a rule is still inventoried. Extensionless shebang files are // scripts; everything else decodable is `unknown`; undecodable bytes are hash-only. - const probe = decodeLossy(raw); if (path.extname(base) === "" && raw.subarray(0, 2).toString("utf-8") === "#!") { format = "text"; roles = ["script"]; - } else if (probe === undefined) { + } else if (text === undefined) { format = "binary"; roles = ["unknown"]; } else { @@ -73,7 +73,6 @@ export function inventoryArtifacts( roles = ["unknown"]; } } - const text = decodeLossy(raw); const capture = opts.artifactText ?? true; const cap = opts.artifactTextMaxBytes ?? DEFAULT_ARTIFACT_TEXT_MAX_BYTES; const textByteLength = text === undefined ? 0 : Buffer.byteLength(text, "utf8");