pburggraf / binary-utils
Binary utilities
v0.5.0
2020-04-10 16:11 UTC
Requires
- php: >=7.2
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ~8.5
README
Class for working with binary data in PHP >=7.2
How to use
<?php require __DIR__ . '/vendor/autoload.php'; use \PBurggraf\BinaryUtilities\BinaryUtilityFactory; use \PBurggraf\BinaryUtilities\DataType\Byte; file_put_contents('/tmp/temp.txt', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $binaryUtility = BinaryUtilityFactory::create(); // Read data $result = $binaryUtility ->setFile('/tmp/temp.txt') ->setOffset(0x08) ->readArray(Byte::class, 4) ->returnBuffer(); var_dump($result); // Expected result: // array(4) { // [0] => // string(2) "56" // [1] => // string(2) "57" // [2] => // string(2) "65" // [3] => // string(2) "66" // } // Write data $binaryUtility ->setOffset(0x08) ->writeArray(Byte::class, [66, 65, 57, 56]) ->save(); var_dump(file_get_contents('/tmp/temp.txt')); // Expected result: // string(36) "01234567BA98CDEFGHIJKLMNOPQRSTUVWXYZ"