MCPcopy Create free account
hub / github.com/LibPDF-js/core / getOrCreateSynthetic

Function getOrCreateSynthetic

benchmarks/fixtures.ts:124–143  ·  view source on GitHub ↗

* Get or create a synthetic PDF cached to disk.

(path: string, pageCount: number)

Source from the content-addressed store, hash-verified

122 * Get or create a synthetic PDF cached to disk.
123 */
124async function getOrCreateSynthetic(path: string, pageCount: number): Promise<Uint8Array> {
125 if (existsSync(path)) {
126 return loadFixture(path);
127 }
128
129 console.log(`Building synthetic ${pageCount}-page PDF...`);
130 const start = performance.now();
131
132 const bytes = await buildSyntheticPdf(pageCount);
133
134 mkdirSync(SYNTHETIC_DIR, { recursive: true });
135 writeFileSync(path, bytes);
136
137 const elapsed = ((performance.now() - start) / 1000).toFixed(1);
138 const size = (bytes.length / 1024 / 1024).toFixed(1);
139
140 console.log(`Cached ${pageCount}-page PDF to ${path} (${size}MB) in ${elapsed}s`);
141
142 return bytes;
143}
144
145/**
146 * Get a synthetic 100-page PDF.

Callers 2

getSynthetic100Function · 0.85
getSynthetic2000Function · 0.85

Calls 2

buildSyntheticPdfFunction · 0.85
loadFixtureFunction · 0.70

Tested by

no test coverage detected