PHPackages                             gh-o-st/bytesize - 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. gh-o-st/bytesize

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

gh-o-st/bytesize
================

A simple conversion library for dealing with digital size units.

00PHP

Since Oct 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/gh-o-st/bytesize)[ Packagist](https://packagist.org/packages/gh-o-st/bytesize)[ RSS](/packages/gh-o-st-bytesize/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Bytesize
========

[](#bytesize)

*A simple conversion library for dealing with digital size units.*

Features
--------

[](#features)

- **Comprehensive Unit Support:** Supports both IEC and SI units, from bits and bytes up to ronabits and ronabytes.
- **Simple API:** Offers a straightforward static method to perform conversions without the need to instantiate classes.

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

[](#requirements)

- **PHP ≥ 8.3:** Leverages modern PHP features, including enums and strict typing.
- **BCMath Extension:** Ensure that the `ext-bcmath` extension is enabled in your PHP installation.

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

[](#installation)

Install Bytesize via Composer:

```
composer require gh-o-st/bytesize
```

Make sure Composer's autoloader is included in your project:

```
require 'vendor/autoload.php';
```

### Error Handling

[](#error-handling)

The `convert` method will throw an `InvalidArgumentException` in the following cases:

- If the value provided is not numeric.
- If the source or target units are invalid or not supported.

```
use InvalidArgumentException;

try {
    $result = SizeConverter::convert('abc', SI::BYTE->value, SI::KILOBYTE->value);
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
}
```

Supported Units
---------------

[](#supported-units)

### SI Units

[](#si-units)

- **Bits `b` and Bytes `B`**
- **Kilobit `Kb` and Kilobyte `KB`**
- **Megabit `Mb` and Megabyte `MB`**
- **Gigabit `Gb` and Gigabyte `GB`**
- **Terabit `Tb` and Terabyte `TB`**
- **Petabit `Pb` and Petabyte `PB`**
- **Exabit `Eb` and Exabyte `EB`**
- **Zetabit `Zb` and Zetabyte `ZB`**
- **Yotabit `Yb` and Yotabyte `YB`**
- **Ronabit `Rb` and Ronabyte `RB`**

### IEC Units

[](#iec-units)

- **Bits `b` and Bytes `B`**
- **Kibibit `Kib` and Kibibyte `KiB`**
- **Mebibit `Mib` and Mebibyte `MiB`**
- **Gibibit `Gib` and Gibibyte `GiB`**
- **Tebibit `Tib` and Tebibyte `TiB`**
- **Pebibit `Pib` and Pebibyte `PiB`**
- **Exbibit `Eib` and Exbibyte `EiB`**
- **Zebibit `Zib` and Zebibyte `ZiB`**
- **Yobibit `Yib` and Yobibyte `YiB`**
- **Ronbibit `Rib` and Ronbibyte `RiB`**

Running Tests
-------------

[](#running-tests)

To run the included test suite, you'll need to have PHPUnit installed:

```
composer install --dev vendor/bin/phpunit
```

License
-------

[](#license)

This project is licensed under the MIT License

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f82033203d0ee8f5196075777269895dcff54a8025fa77025f0a792ffef3125?d=identicon)[gh-o-st](/maintainers/gh-o-st)

---

Top Contributors

[![gh-o-st](https://avatars.githubusercontent.com/u/6260598?v=4)](https://github.com/gh-o-st "gh-o-st (2 commits)")

### Embed Badge

![Health badge](/badges/gh-o-st-bytesize/health.svg)

```
[![Health](https://phpackages.com/badges/gh-o-st-bytesize/health.svg)](https://phpackages.com/packages/gh-o-st-bytesize)
```

PHPackages © 2026

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