|
| 1 | +# kduma/pcf-dcp — PCF Dynamic Container Partition (PHP) |
| 2 | + |
| 3 | +PHP reader/writer for **PCF-DCP v1.0**, an application-level profile that adds |
| 4 | +*dynamic*, fragmentable, dedup-friendly sub-partitions to the |
| 5 | +[Partitioned Container Format](https://github.com/kduma-OSS/Partitioned-Container-Format) |
| 6 | +(`kduma/pcf`) without modifying the PCF byte container. |
| 7 | + |
| 8 | +This package mirrors the written specification (`PCF-DCP-spec-v1.0.txt`) and the |
| 9 | +Rust reference implementation field-for-field, and ships the same byte-exact |
| 10 | +700-byte canonical test vector as every other port. It has no cryptographic |
| 11 | +dependency — data/table hashing comes from `kduma/pcf` (`ext-hash`). |
| 12 | + |
| 13 | +## Model at a glance |
| 14 | + |
| 15 | +One new PCF partition type is defined: |
| 16 | + |
| 17 | +| Type | Name | Holds | |
| 18 | +|--------------|-----------------|----------------------------------------------------| |
| 19 | +| `0xAAAC0001` | `DCP_CONTAINER` | An *arena*: a header, an inner partition table, fragment tables, and data extents | |
| 20 | + |
| 21 | +``` |
| 22 | +arena: |
| 23 | +[ DCP Header (24 B) | data extents | Fragment Tables | Inner Table Block(s) ] |
| 24 | +``` |
| 25 | + |
| 26 | +Each inner partition's logical content is the concatenation of its DATA extents; |
| 27 | +its data hash covers that logical content, so fragmentation, deduplication, |
| 28 | +compaction, and promotion all leave the hash (and any PCF-SIG signature over it) |
| 29 | +unchanged. A generic PCF reader sees a DCP file as **one opaque partition**; only |
| 30 | +a DCP-aware reader looks inside. |
| 31 | + |
| 32 | +## Example |
| 33 | + |
| 34 | +```php |
| 35 | +use Kduma\PCF\HashAlgo; |
| 36 | +use Kduma\PCF\Storage\MemoryStorage; |
| 37 | +use Kduma\PCFDCP\Arena; |
| 38 | +use Kduma\PCFDCP\Chunker; |
| 39 | +use Kduma\PCFDCP\DcpReader; |
| 40 | +use Kduma\PCFDCP\DcpWriter; |
| 41 | + |
| 42 | +$arena = new Arena(); |
| 43 | +$arena->addInner(0x10, str_repeat("\xA1", 16), 'A', 'Hello, World!', HashAlgo::Sha256, Chunker::fixed(7)); |
| 44 | +$arena->addInner(0x10, str_repeat("\xB2", 16), 'B', 'World!', HashAlgo::Sha256, Chunker::whole()); |
| 45 | + |
| 46 | +$w = new DcpWriter(); |
| 47 | +$w->addContainer(str_repeat("\xDC", 16), 'dcp', $arena); |
| 48 | +$image = $w->toImage(); |
| 49 | + |
| 50 | +$r = DcpReader::open(new MemoryStorage($image)); |
| 51 | +$r->verify(); |
| 52 | +echo $r->readInner(str_repeat("\xB2", 16)); // "World!" |
| 53 | +``` |
| 54 | + |
| 55 | +## Operations |
| 56 | + |
| 57 | +`Arena` supports content-defined deduplication, copy-on-write edits |
| 58 | +(`append` / `insert` / `overwrite` / `delete` / `truncate`), and |
| 59 | +sharing-preserving `compact`. `DcpWriter` adds **promotion** (`promote`, |
| 60 | +dynamic → fixed) and **demotion** (`demote`, fixed → dynamic), each preserving |
| 61 | +`uid`, `partitionType`, `label`, `dataHashAlgo`, and `dataHash` — the promotion |
| 62 | +invariant, identical to the fields a PCF-SIG signature protects. |
| 63 | + |
| 64 | +## Licence |
| 65 | + |
| 66 | +MIT. |
0 commit comments