pdf-codec 3.1.1 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -87,6 +87,8 @@ An encrypted PDF that opens without a password decrypts transparently — no ext
87
87
 
88
88
  Both accept an optional `signal` (`AbortSignal`); `readPdf` additionally takes a `sink` (`PdfDiagnosticSink`, called once per recoverable parse diagnostic — see the three-tier failure policy under [Conventions](#conventions)), and `writePdf` an `onSubstitution` callback (called once per character not representable in a standard-14 font — see [Fidelity](#fidelity)).
89
89
 
90
+ **Cancellation granularity and cost, for CPU-metered runtimes.** Both pipelines are synchronous end to end — there is no `await` point for cancellation to hook into implicitly — so the `signal` is checked explicitly, once per page-loop iteration (and once before `readPdf`'s document-open phase begins). A signal aborted mid-parse therefore takes effect at the next page boundary, not instantly: `readPdf`'s document-open phase (cross-reference resolution, object parsing) and a single page's content-stream interpretation are the two spans that cannot be interrupted, and a document consisting of one enormous page is effectively uninterruptible however many pages it claims. Cost is roughly linear in decompressed content length, so budget for the worst single page, not the page count. On Cloudflare Workers this is the honest shape of the trade: the parse holds the isolate for its whole duration with no opportunity to yield or report progress, and an `AbortSignal` shared with whatever can abort concurrently (a binding, another context) makes a deadline enforceable at page granularity — but it cannot convert a synchronous parse into a resumable one. An async page-at-a-time API is a deliberate non-goal of this package's current surface.
91
+
90
92
  The same round trip is also available as a schema-validated [`z.codec()`](https://zod.dev) pair:
91
93
 
92
94
  ```ts
package/dist/read.cjs CHANGED
@@ -30,6 +30,7 @@ function readPdf(bytes, options) {
30
30
  const sink = options?.sink ?? require_diagnostics.NOOP_DIAGNOSTIC_SINK;
31
31
  const signal = options?.signal;
32
32
  if (!hasPdfHeader(bytes)) throw new require_diagnostics.PdfParseError("pdf/no-header", "no \"%PDF-\" header found within the first bytes of the file; this does not look like a PDF at all");
33
+ require_util_abort.throwIfAborted(signal);
33
34
  const doc = require_document.openPdfDocument(bytes, sink);
34
35
  const fontResolver = require_font_read.createFontResolver({
35
36
  resolver: doc,
package/dist/read.js CHANGED
@@ -29,6 +29,7 @@ function readPdf(bytes, options) {
29
29
  const sink = options?.sink ?? NOOP_DIAGNOSTIC_SINK;
30
30
  const signal = options?.signal;
31
31
  if (!hasPdfHeader(bytes)) throw new PdfParseError("pdf/no-header", "no \"%PDF-\" header found within the first bytes of the file; this does not look like a PDF at all");
32
+ throwIfAborted(signal);
32
33
  const doc = openPdfDocument(bytes, sink);
33
34
  const fontResolver = createFontResolver({
34
35
  resolver: doc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-codec",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on its own codec-owned LayoutDocument item model and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -98,7 +98,7 @@
98
98
  "packageManager": "pnpm@11.6.0",
99
99
  "dependencies": {
100
100
  "byte-codec": "^1.1.13",
101
- "document-schema.js": "^4.5.0",
101
+ "document-schema.js": "^4.6.0",
102
102
  "fflate": "^0.8.3",
103
103
  "zod": "^4.4.3"
104
104
  },