Initial release of File Tools 0.1.0

This commit is contained in:
2026-09-01 02:55:06 +02:00
commit 055f533cf1
62 changed files with 9050 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
import type { FileInspection } from "./protocol";
export interface FileRecord {
name: string;
path: string;
size: number;
type: string;
lastModified: number;
inspection?: FileInspection;
sha256?: string;
sha512?: string;
}
export function manifestJson(records: FileRecord[]): string {
return JSON.stringify(
{
schemaVersion: 1,
generatedBy: "add-ideas File Tools 0.1.0",
files: [...records]
.sort((left, right) => left.path.localeCompare(right.path))
.map((record) => ({
path: record.path,
size: record.size,
lastModified: new Date(record.lastModified).toISOString(),
claimedMime: record.type || null,
detectedMime: record.inspection?.detected?.mime ?? null,
sha256: record.sha256 ?? null,
sha512: record.sha512 ?? null,
findings: record.inspection?.findings ?? [],
})),
},
null,
2,
);
}
function csv(value: unknown): string {
const text = String(value ?? "");
const safe = /^[=+\-@\t\r]/u.test(text) ? `'${text}` : text;
return `"${safe.replaceAll('"', '""')}"`;
}
export function manifestCsv(records: FileRecord[]): string {
const lines = [
[
"path",
"size",
"lastModified",
"claimedMime",
"detectedMime",
"sha256",
"sha512",
]
.map(csv)
.join(","),
];
for (const record of [...records].sort((left, right) =>
left.path.localeCompare(right.path),
))
lines.push(
[
record.path,
record.size,
new Date(record.lastModified).toISOString(),
record.type,
record.inspection?.detected?.mime,
record.sha256,
record.sha512,
]
.map(csv)
.join(","),
);
return lines.join("\r\n") + "\r\n";
}