gh-o-st / bytesize
A simple conversion library for dealing with digital size units.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/gh-o-st/bytesize
Requires
- php: >=8.3
- ext-bcmath: *
Requires (Dev)
- phpstan/phpstan: @stable
- phpunit/phpunit: @stable
This package is auto-updated.
Last update: 2025-11-15 20:33:16 UTC
README
A simple conversion library for dealing with digital size units.
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
- PHP ≥ 8.3: Leverages modern PHP features, including enums and strict typing.
- BCMath Extension: Ensure that the
ext-bcmathextension is enabled in your PHP 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
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
SI Units
- Bits
band BytesB - Kilobit
Kband KilobyteKB - Megabit
Mband MegabyteMB - Gigabit
Gband GigabyteGB - Terabit
Tband TerabyteTB - Petabit
Pband PetabytePB - Exabit
Eband ExabyteEB - Zetabit
Zband ZetabyteZB - Yotabit
Yband YotabyteYB - Ronabit
Rband RonabyteRB
IEC Units
- Bits
band BytesB - Kibibit
Kiband KibibyteKiB - Mebibit
Miband MebibyteMiB - Gibibit
Giband GibibyteGiB - Tebibit
Tiband TebibyteTiB - Pebibit
Piband PebibytePiB - Exbibit
Eiband ExbibyteEiB - Zebibit
Ziband ZebibyteZiB - Yobibit
Yiband YobibyteYiB - Ronbibit
Riband RonbibyteRiB
Running Tests
To run the included test suite, you'll need to have PHPUnit installed:
composer install --dev vendor/bin/phpunit
License
This project is licensed under the MIT License