PHPackages                             hardcastle/buffer - 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. hardcastle/buffer

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

hardcastle/buffer
=================

PHP implementation of the NodeJS Buffer class

1.0.0(1mo ago)29.0k↓23.3%2MITPHPPHP ^8.2CI passing

Since Dec 8Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/AlexanderBuzz/Buffer)[ Packagist](https://packagist.org/packages/hardcastle/buffer)[ RSS](/packages/hardcastle-buffer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (5)Used By (2)

Buffer
======

[](#buffer)

PHP implementation of the Node.js Buffer module, available for PHP 8.2+.

Features
--------

[](#features)

- Fully compliant with Node.js Buffer API.
- Supports various encodings: `utf8`, `hex`, `base64`.
- Memory-efficient storage using `SplFixedArray`.
- Supports reading and writing various data types:
    - Integers: `Int8`, `UInt8`, `Int16BE/LE`, `UInt16BE/LE`, `Int32BE/LE`, `UInt32BE/LE`.
    - Floats &amp; Doubles: `FloatBE/LE`, `DoubleBE/LE`.
- Utility methods: `fill`, `write`, `copy`, `compare`, `indexOf`, `lastIndexOf`, `includes`, `swap16/32/64`.
- `ArrayAccess` implementation for easy byte access.

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

[](#installation)

```
composer require hardcastle/buffer
```

Usage
-----

[](#usage)

### Create Buffer

[](#create-buffer)

```
use Hardcastle\Buffer\Buffer;

// From size
$buf = Buffer::alloc(10);

// From array
$buf = Buffer::from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);

// From string
$buf = Buffer::from('hello world', 'utf8');

// From hex
$buf = Buffer::from('627566666572', 'hex');

// From base64
$buf = Buffer::from('aGVsbG8=', 'base64');
```

### Access &amp; Modification

[](#access--modification)

```
$buf = Buffer::alloc(10);
$buf[0] = 0x41; // 'A'
echo $buf[0]; // 65
echo $buf->length; // 10

$buf->write('hello', 1);
echo $buf->toUtf8(); // Ahello
```

### Reading &amp; Writing

[](#reading--writing)

```
$buf = Buffer::alloc(4);
$buf->writeInt32BE(0x12345678, 0);
echo dechex($buf->readInt32BE(0)); // 12345678
```

License
-------

[](#license)

MIT

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance88

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

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.

###  Release Activity

Cadence

Every ~277 days

Total

4

Last Release

59d ago

Major Versions

0.2.0 → 1.0.02026-03-20

PHP version history (2 changes)0.1.0PHP ^8.1

1.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/3df9851b05573ab236b96118bf83edd2c6a8f50a41a6372f2d0c8241de2dd56a?d=identicon)[alexander.busse](/maintainers/alexander.busse)

---

Top Contributors

[![AlexanderBuzz](https://avatars.githubusercontent.com/u/102560752?v=4)](https://github.com/AlexanderBuzz "AlexanderBuzz (7 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hardcastle-buffer/health.svg)

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

###  Alternatives

[ramsey/uuid

A PHP library for generating and working with universally unique identifiers (UUIDs).

12.6k700.2M3.3k](/packages/ramsey-uuid)[brick/money

Money and currency library

1.9k37.9M102](/packages/brick-money)[pascaldevink/shortuuid

PHP 7.4+ library that generates concise, unambiguous, URL-safe UUIDs

5951.8M15](/packages/pascaldevink-shortuuid)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

374468.4k51](/packages/flow-php-etl)[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.3k](/packages/blair2004-nexopos)[spomky-labs/cbor-php

CBOR Encoder/Decoder for PHP

596.4M30](/packages/spomky-labs-cbor-php)

PHPackages © 2026

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