mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
* fix(remote-files): open HTML, PDFs and images too large for one reply on a paired runtime files.read stops at 512 KiB and files.readPreview at about 3 MB (one 4 MiB reply, after base64), so larger files on a paired runtime failed to open. Read them in chunks with the files.stat and files.readChunk methods hosts already have, and refuse a save the host's 1 MiB frame cap would answer by closing the connection. Fixes #29306 Fixes #26062 Co-authored-by: sotashimozono <shimozono-sota631@g.ecc.u-tokyo.ac.jp> * fix(remote-files): keep a UTF-8 BOM when paging a large remote text file * fix(remote-files): pin a paged read to one pairing and compare ctime * fix(remote-files): pin the pairing before a remote read's first request --------- Co-authored-by: sotashimozono <shimozono-sota631@g.ecc.u-tokyo.ac.jp>
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
export function createPdfFindFixture({
|
|
title = 'PDF search fixture',
|
|
/** Grows the file with a stream no page references, for size-dependent paths. */
|
|
paddingBytes = 0
|
|
} = {}): Buffer {
|
|
const objects = [
|
|
'<< /Type /Catalog /Pages 2 0 R >>',
|
|
'<< /Type /Pages /Kids [4 0 R 6 0 R 8 0 R] /Count 3 >>',
|
|
'<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>'
|
|
]
|
|
for (let page = 0; page < 3; page += 1) {
|
|
const contentId = 5 + page * 2
|
|
objects.push(
|
|
`<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 3 0 R >> >> /Contents ${contentId} 0 R >>`
|
|
)
|
|
const lines = [
|
|
`${title} - page ${page + 1}`,
|
|
`needle result ${page * 2 + 1}`,
|
|
`needle result ${page * 2 + 2}`,
|
|
page === 1 ? 'Plain text without the alternate query' : 'beacon alternate query'
|
|
]
|
|
const stream = `BT /F1 20 Tf 60 700 Td 40 TL ${lines.map((line) => `(${line}) Tj T*`).join(' ')} ET\n`
|
|
objects.push(`<< /Length ${Buffer.byteLength(stream)} >>\nstream\n${stream}endstream`)
|
|
}
|
|
if (paddingBytes > 0) {
|
|
objects.push(`<< /Length ${paddingBytes} >>\nstream\n${'x'.repeat(paddingBytes)}\nendstream`)
|
|
}
|
|
let pdf = '%PDF-1.4\n'
|
|
const offsets = [0]
|
|
for (const [index, object] of objects.entries()) {
|
|
offsets.push(Buffer.byteLength(pdf))
|
|
pdf += `${index + 1} 0 obj\n${object}\nendobj\n`
|
|
}
|
|
const xref = Buffer.byteLength(pdf)
|
|
pdf += `xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`
|
|
pdf += offsets
|
|
.slice(1)
|
|
.map((offset) => `${String(offset).padStart(10, '0')} 00000 n \n`)
|
|
.join('')
|
|
pdf += `trailer\n<< /Size ${objects.length + 1} /Root 1 0 R >>\nstartxref\n${xref}\n%%EOF\n`
|
|
return Buffer.from(pdf)
|
|
}
|