PHPackages                             tiamo/bytebuffer - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tiamo/bytebuffer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tiamo/bytebuffer
================

PHP Byte Buffer

51.9kPHP

Since Mar 14Pushed 9y agoCompare

[ Source](https://github.com/tiamo/bytebuffer)[ Packagist](https://packagist.org/packages/tiamo/bytebuffer)[ RSS](/packages/tiamo-bytebuffer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

ByteBuffer
==========

[](#bytebuffer)

A PHP library for reading and writing binary streams.

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

[](#requirements)

- PHP 5.3.0 and up.
- bcmath extension

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist tiamo/bytebuffer "*"

```

or add

```
"tiamo/bytebuffer": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Writer example:

```
// create a new empty stream (php://temp)
$stream = \ByteBuffer\Stream::factory('', [
    'charset' => 'cp1251' // optional, default string data charset
]);
$stream->isLittleEndian = false; // default value is true
$stream->write('pure bytes');
$stream->writeBytes([255, 255, 255, 1]);
$stream->writeString('hello');
$stream->writeString('привет', 'cp1251'); // optional, custom charset
$stream->writeInt(1, 8);  // int8 (1 byte)
$stream->writeInt(1, 16); // int16 (2 bytes)
$stream->writeInt(1, 24); // int24 (3 bytes)
$stream->writeInt(1, 32); // int32 (4 bytes)
$stream->writeInt(1, 64); // int64 (8bytes)
$stream->writeFloat(1.234);
$stream->writeDouble(12345.6789);
$stream->writeNull(3);
$stream->save('data.bin');
```

Reader example:

```
$stream = \ByteBuffer\Stream::factory(fopen('data.bin', 'r+'));
$stream->read(10);
$stream->readBytes(4); // [255, 255, 255, 1]
$stream->readString(5); // hello
$stream->readInt(8); // read unsigned int8
$stream->readInt(16, false); // read signed int8
// ...
$stream->readFloat();
$stream->readDouble();
$stream->skip(3);
```

Allocate and pipe example:

```
$stream = \ByteBuffer\Stream::factory(fopen('data.bin', 'r+'));
$newStream = $stream->allocate(10); // allocate new buffer in memory
$newStream->readString(4); // = pure

$stream->pipe($newStream);
$stream->readBytes(4); // = [255, 255, 255 ,1]
```

Network example:

```
$stream = \ByteBuffer\Stream::factory(fsockopen('google.com', 80));
$stream->readBytes(4);
```

Remote file example:

```
$stream = \ByteBuffer\Stream::factory(fopen('http://..../image.jpg', 'r'));
$bytes = $stream->readBytes(2);
if ($bytes[0] == 0xff && $bytes[1] == 0xd8) {
   echo 'valid jpeg!';
}
```

TODO
----

[](#todo)

- tests

License
-------

[](#license)

Licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4556300c975051e548119ba8e4d39204d615080c441a6518ef66e866cd3cba9e?d=identicon)[tiamo](/maintainers/tiamo)

---

Top Contributors

[![tiamo](https://avatars.githubusercontent.com/u/1963342?v=4)](https://github.com/tiamo "tiamo (11 commits)")

---

Tags

binarybufferstream

### Embed Badge

![Health badge](/badges/tiamo-bytebuffer/health.svg)

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

###  Alternatives

[pedrotroller/php-cs-custom-fixer

PHP-CS-FIXER : my custom fixers

811.0M53](/packages/pedrotroller-php-cs-custom-fixer)[lkallas/estonianpin

A simple library for processing Estonian Personal Identification Code (isikukood).

1615.7k](/packages/lkallas-estonianpin)

PHPackages © 2026

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