Files
claude-code-haha/src/tools/FileReadTool/fixtures/asciiPDF.ts
T
2026-10-01 17:45:25 +08:00

22 lines
1.1 KiB
TypeScript

// Valid ASCII PDF content, with byte offsets and stream length computed so
// Write can replace it without binary transcoding or repairing the xref.
export function asciiPDF(label: string): string {
const stream = `BT /F1 20 Tf 60 760 Td (${label}) Tj ET\n`
const objects = [
'<< /Type /Catalog /Pages 2 0 R >>',
'<< /Type /Pages /Kids [3 0 R] /Count 1 >>',
'<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] /Resources << /Font << /F1 4 0 R >> >> /Contents 5 0 R >>',
'<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>',
`<< /Length ${Buffer.byteLength(stream)} >>\nstream\n${stream}endstream`,
]
let content = '%PDF-1.4\n'
const offsets: number[] = []
for (const [index, object] of objects.entries()) {
offsets.push(Buffer.byteLength(content))
content += `${index + 1} 0 obj\n${object}\nendobj\n`
}
const xref = Buffer.byteLength(content)
content += `xref\n0 6\n0000000000 65535 f \n${offsets.map(offset => `${String(offset).padStart(10, '0')} 00000 n \n`).join('')}`
return `${content}trailer\n<< /Size 6 /Root 1 0 R >>\nstartxref\n${xref}\n%%EOF\n`
}