Implements Phase 6.9.1: the two-byte-prefix directory scheme that keeps any single directory under 65K entries even at millions of cached entries. Changes: - Add zstd dependency to Cargo.toml - Create cache module with layout.rs implementing path construction - Add CacheIndex struct for index.json metadata (schema version, timestamps) - Implement entry_path(), fingerprint_dir(), parse helpers - Add load_index()/save_index() for cache metadata persistence - Ensure mkdir -p semantics with ensure_fingerprint_dir() - 18 tests covering all acceptance criteria Acceptance criteria verified: ✓ entry_path produces correct two-level prefix layout ✓ Different opts_hashes for same fingerprint share fp_dir ✓ Different fingerprints with same prefix share first-level dir ✓ index.json round-trips with schema version check ✓ Future schema version rejects cache with clear error ✓ mkdir -p creates prefix dirs; idempotent on concurrent writes ✓ Unicode-correct path handling via std::path::PathBuf ✓ Path length stays under 4096 bytes Co-Authored-By: Claude Code <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| examples | ||
| proptest-regressions/parser/lexer | ||
| src | ||
| tests | ||
| Cargo.toml | ||
| pdftract-core.cdx.json | ||
| README.md | ||
pdftract-core
The core Rust library for PDF text extraction. This crate provides the parsing, layout analysis, font encoding recovery, and text extraction primitives used by the CLI (pdftract-cli) and Python bindings (pdftract-py).
Cargo.lock Policy
This workspace checks in Cargo.lock at the repository root. This is unconventional for library crates—the Cargo Book historically suggested that only binary crates should check in lockfiles, allowing library consumers to resolve their own dependency versions.
pdftract departs from this convention for release reproducibility:
-
SLSA Level 3 provenance requires that every milestone tag produces byte-identical artifacts across builds. Without a checked-in lockfile, two runs of
cargo buildon the same commit can resolve different transitive dependency versions, producing different binary hashes. -
Multi-output artifacts—this workspace produces Rust crates (
pdftract-core,pdftract-cli), Python wheels (pdftract-py), and Docker images. All must be built from the same dependency tree. -
Supply-chain security—the lockfile pins checksums for all transitive dependencies, enabling
cargo auditto detect yanked or compromised crates. -
Downstream consumers can still ignore the lockfile if needed. Cargo allows
cargo build --frozenwith a local lockfile override, or consumers can vendor the crate with their own dependency resolution.
The tradeoff—occasional merge conflicts when PRs update overlapping dependencies—is worth the guarantee of reproducible releases. See CONTRIBUTING.md for the lockfile-update workflow.
Modules
parser: PDF spec parsing (xref, trailer, object streams, indirect references)font: Font encoding recovery, glyph name lookup, fingerprintinglayout: Page layout analysis, region segmentation, reading orderextract: Text extraction with provenance (bounding boxes, confidence scores)ocr: Tesseract integration for raster pages
Usage
use pdftract_core::{extract_text, ExtractOptions};
let options = ExtractOptions::default();
let result = extract_text("document.pdf", &options)?;
println!("{}", result.text);