* Create a mock object stream with the given objects. * Index format: objNum1 offset1 objNum2 offset2 ... * Objects are stored as text representations.
(objects: Array<{ objNum: number; text: string }>)
| 14 | * Objects are stored as text representations. |
| 15 | */ |
| 16 | function createObjectStream(objects: Array<{ objNum: number; text: string }>): PdfStream { |
| 17 | // Build index and object sections |
| 18 | const indexParts: string[] = []; |
| 19 | const objectParts: string[] = []; |
| 20 | let currentOffset = 0; |
| 21 | |
| 22 | for (const { objNum, text } of objects) { |
| 23 | indexParts.push(`${objNum} ${currentOffset}`); |
| 24 | objectParts.push(text); |
| 25 | // Add 1 for the newline separator |
| 26 | currentOffset += new TextEncoder().encode(text).length + 1; |
| 27 | } |
| 28 | |
| 29 | const indexSection = `${indexParts.join(" ")}\n`; |
| 30 | const objectSection = objectParts.join("\n"); |
| 31 | const fullContent = indexSection + objectSection; |
| 32 | |
| 33 | const data = new TextEncoder().encode(fullContent); |
| 34 | const first = new TextEncoder().encode(indexSection).length; |
| 35 | |
| 36 | // Create stream dictionary |
| 37 | const stream = new PdfStream( |
| 38 | [ |
| 39 | ["Type", PdfName.of("ObjStm")], |
| 40 | ["N", PdfNumber.of(objects.length)], |
| 41 | ["First", PdfNumber.of(first)], |
| 42 | ], |
| 43 | data, |
| 44 | ); |
| 45 | |
| 46 | return stream; |
| 47 | } |
| 48 | |
| 49 | describe("ObjectStreamParser", () => { |
| 50 | describe("constructor", () => { |
no test coverage detected