PHPackages                             kduma/pcf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. kduma/pcf

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

kduma/pcf
=========

PHP implementation of the Partitioned Container Format (PCF) v1.0

v0.0.9(1mo ago)03MITPHPPHP &gt;=8.1

Since Jun 6Pushed 1mo agoCompare

[ Source](https://github.com/kduma-OSS-splits/PHP-PCF-lib)[ Packagist](https://packagist.org/packages/kduma/pcf)[ Docs](https://github.com/kduma-OSS/Partitioned-Container-Format)[ RSS](/packages/kduma-pcf/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

pcf — Partitioned Container Format (PHP implementation)
=======================================================

[](#pcf--partitioned-container-format-php-implementation)

PHP reader/writer for **PCF v1.0**, a language-agnostic binary container that stores multiple independent byte regions ("partitions") in one file.

This is the first PHP port of the format. It mirrors the written specification (`specs/PCF-spec-v1.0.txt`) and the Rust reference (`reference/PCF-v1.0/`) field-for-field, and it reproduces the canonical 395-byte test vector from spec section 15 **byte-for-byte**. It favours auditability over performance.

Layout
------

[](#layout)

```
[ 20-byte header ] [ table block(s) ] [ partition data regions ]

```

- **Header** (20 B): magic `0x89 K P R T 0x0D 0x0A 0x1A`, major/minor version, absolute offset of the first table block.
- **Table block**: 74-byte header (`partition_count`, `next_table_offset`, hash algo + 64-byte block hash) followed by `partition_count` entries. Blocks form a singly linked chain to hold more than 255 partitions.
- **Entry** (141 B): `type`, 16-byte UID, 32-byte ASCII label, `start_offset`, `max_length`, `used_bytes`, 1-byte data-hash algorithm, 64-byte data hash.

All integers are little-endian. Free space is `max_length - used_bytes`.

Hash registry
-------------

[](#hash-registry)

idalgorithmidalgorithm0none5SHA-11CRC-32/ISO-HDLC16SHA-256 (default)2CRC-32C17SHA-5123CRC-64/XZ18BLAKE34MD5Most algorithms come from PHP's bundled `ext-hash`. The two it does not provide:

- **CRC-64/XZ** — `Kduma\PCF\Crc64` (check value `0x995DC9BBDF1939FA`), shipped pure-PHP and validated against the canonical check vector.
- **BLAKE3** — delegated to the `tourze/blake3-php` Composer package, wrapped behind `HashAlgo::blake3()` so the dependency is isolated to one method.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1 with `ext-hash` (bundled by default).
- Composer (for the BLAKE3 dependency).

Installation
------------

[](#installation)

```
composer require kduma-oss/pcf
```

Usage
-----

[](#usage)

```
use Kduma\PCF\Container;
use Kduma\PCF\HashAlgo;
use Kduma\PCF\Storage\MemoryStorage;
use Kduma\PCF\Storage\StreamStorage;

// In-memory container.
$c = Container::create(new MemoryStorage());
$uid = str_repeat("\x01", 16);
$c->addPartition(0x10, $uid, 'notes', 'hello world', 64, HashAlgo::Sha256);

$c->verify();
$entries = $c->entries();
echo $c->readPartitionData($entries[0]); // "hello world"

// File-backed container.
$f = Container::create(StreamStorage::fromFile('container.pcf', 'c+'));
$f->addPartition(0xFFFFFFFF, str_repeat("\x02", 16), 'blob', "\x00\x01\x02", 0, HashAlgo::Crc32c);
$f->verify();

// Reclaim dead space into the canonical compacted layout.
$image = $c->compactedImage();
file_put_contents('compacted.pcf', $image);
```

`Container` works over any `Kduma\PCF\Storage\StorageInterface`:

- `MemoryStorage` — an in-memory string buffer (analogue of the reference's `Cursor`).
- `StreamStorage` — any seekable PHP stream / file (analogue of `std::fs::File`).

### Operations

[](#operations)

MethodPurpose`Container::create()` / `createWith()`Start an empty container.`Container::open()`Open an existing one (validates magic + major version).`addPartition()`Append a partition (unique non-NIL UID, non-reserved type).`updatePartitionData()`Replace data in place; maintains the hash cascade.`removePartition()`Remove a partition (data region becomes dead space).`entries()` / `readPartitionData()`Read metadata and data.`verify()`Verify every table-block and partition hash + conformance checks.`compactedImage()` / `compactInto()`Produce the tightly packed canonical form.Errors are reported as `Kduma\PCF\PcfException`; the precise cause is available as `$e->kind` (a `Kduma\PCF\ErrorKind`).

Tests
-----

[](#tests)

```
composer install
composer test                       # or: vendor/bin/phpunit
php examples/gen_testvector.php out.bin   # writes the canonical 395-byte file
```

The suite mirrors the Rust reference:

```
implementations/php/pcf/
├── composer.json
├── src/                      # library sources
├── examples/
│   └── gen_testvector.php    # produces the canonical spec test vector
└── tests/
    ├── HashTest.php          # hash registry + CRC/BLAKE3 vectors
    ├── HeaderTest.php        # 20-byte file header
    ├── EntryTest.php         # 141-byte entry + labels
    ├── TableTest.php         # 74-byte table block + table hash
    ├── RoundtripTest.php     # end-to-end create/open/update/remove/compact
    └── SpecComplianceTest.php# one test per normative MUST/SHALL + byte-exact vector

```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d09451622719c7efce1a7971b8e5a875859504882ba2b8c279d1015a99e8f12c?d=identicon)[kduma](/maintainers/kduma)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")

---

Tags

containerbinaryfile-formatpcfpartitioned-container-format

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kduma-pcf/health.svg)

```
[![Health](https://phpackages.com/badges/kduma-pcf/health.svg)](https://phpackages.com/packages/kduma-pcf)
```

###  Alternatives

[psr/container

Common Container Interface (PHP FIG PSR-11)

10.0k1.1B4.9k](/packages/psr-container)[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k134.5M1.4k](/packages/pimple-pimple)[php-di/php-di

The dependency injection container for humans

2.8k55.5M1.3k](/packages/php-di-php-di)[league/container

A fast and intuitive dependency injection container.

86894.4M448](/packages/league-container)[dvdoug/boxpacker

An implementation of the 3D (actually 4D) bin packing/knapsack problem (aka creating parcels by putting items into boxes)

6562.9M26](/packages/dvdoug-boxpacker)[league/tactician-container

Tactician integration for any container implementing PSR-11

7710.4M24](/packages/league-tactician-container)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
