MCPcopy Index your code
hub / github.com/LibPDF-js/core / createObjectStream

Function createObjectStream

src/parser/object-stream-parser.test.ts:16–47  ·  view source on GitHub ↗

* 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 }>)

Source from the content-addressed store, hash-verified

14 * Objects are stored as text representations.
15 */
16function 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
49describe("ObjectStreamParser", () => {
50 describe("constructor", () => {

Callers 1

Calls 3

pushMethod · 0.80
encodeMethod · 0.65
ofMethod · 0.45

Tested by

no test coverage detected