bytes icon indicating copy to clipboard operation
bytes copied to clipboard

A class to help convert bytes into other units (kb, mb, etc).

A class to help convert bytes into other units (kb, mb, etc).

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package can be used to convert int|float values from bytes to KB, MB and GB as well as KiB, MiB and GiB.

Installation

You can install the package via Composer:

composer require ryangjchandler/bytes

Usage

You can instantiate a new Converter class via the new keyword or the static Converter::from constructor.

use RyanChandler\Bytes\Converter;

$converter = new Converter(1_000);

$converter = Converter::from(1_000);

You can then use the available methods to convert from bytes to KB, MB, GB, KiB, MiB or GiB.

$kb = $converter->toKb();
$kib = $converter->toKiB();
$mb = $converter->toMb();
$mib = $converter->toMiB();
$gb = $converter->toGb();
$gib = $converter->toGiB();

Testing

composer test:unit

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.