Add PHP implementation of PCF v1.0 (Partitioned Container Format)#5
Merged
Conversation
Port the Partitioned Container Format v1.0 reader/writer to PHP under implementations/php/, mirroring the spec and the Rust reference field-for-field. The library reproduces the canonical 395-byte test vector from spec section 15 byte-for-byte. Highlights: - PSR-4 library (namespace Kduma\PCF): FileHeader, TableBlockHeader, PartitionEntry, HashAlgo registry, and a Container with create/open/add/update/remove/verify/compaction. - Storage abstraction (MemoryStorage, StreamStorage) so containers work in memory or over any seekable stream/file. - Zero runtime Composer dependencies beyond ext-hash: CRC-64/XZ and BLAKE3 are shipped pure-PHP and validated against canonical vectors (CRC-64 check value 0x995DC9BBDF1939FA; all 35 official BLAKE3 vectors). - PHPUnit suite (85 tests) ported from the reference roundtrip, coverage, and spec-compliance suites, plus a gen_testvector example. - New GitHub Actions workflow (PHP 8.1-8.4) running PHPUnit and checking the 395-byte test vector. https://claude.ai/code/session_018yzCMkuQCHA2h8iEkQAota
Drop the in-tree BLAKE3 port in favor of the `tourze/blake3-php` Composer package, wrapped behind a private `HashAlgo::blake3()` helper so the dependency is isolated to a single call site. Update tests and README to reflect the new source of the BLAKE3 implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a complete PHP implementation of the Partitioned Container Format (PCF) v1.0 specification, mirroring the reference Rust implementation field-for-field and reproducing the canonical test vector byte-for-byte.
Summary
The implementation provides a full-featured reader/writer for PCF files—a language-agnostic binary container format that stores multiple independent byte regions ("partitions") in a single file. The library is production-ready, fully spec-compliant, and extensively tested.
Key Changes
Core Container API (
Container.php): High-level interface for creating, opening, reading, and modifying PCF files with support for:Data Structures: Complete implementation of all PCF on-disk formats:
FileHeader.php: 20-byte file header with magic, version, and table offsetTableBlockHeader.php: 74-byte table-block header with partition count and chainingPartitionEntry.php: 141-byte partition entry with type, UID, label, offsets, and data hashHash Algorithm Registry (
HashAlgo.php): Support for 9 algorithms per spec section 8:Crc64.php)tourze/blake3-php)Storage Abstraction (
Storage/): Two implementations ofStorageInterface:MemoryStorage: In-memory string buffer for building containers and testingStreamStorage: Seekable stream wrapper for file-based I/OError Handling (
PcfException.php,ErrorKind.php): Single exception type with discriminated error kinds for precise error branchingComprehensive Test Suite:
SpecComplianceTest.php: 30+ tests tracing to specific MUST/SHALL clauses in the specRoundtripTest.php: End-to-end container lifecycle tests (create, add, read, verify, reopen)HashTest.php: Hash algorithm validation with known test vectorsEntryTest.php,HeaderTest.php,TableTest.php: Low-level format testsTooling:
examples/gen_testvector.php: Generates the canonical 395-byte test vector from spec section 15.github/workflows/php.yml: CI pipeline testing PHP 8.1–8.4composer.json: Dependency management with PHPUnit and BLAKE3 supportNotable Implementation Details
https://claude.ai/code/session_018yzCMkuQCHA2h8iEkQAota