componenta/byte
Composer 安装命令:
composer require componenta/byte
包简介
Byte, information unit, and bit-rate value objects
README 文档
README
Information-size and transfer-rate value objects.
The package contains:
Bytefor data sizes stored internally as bytesByteUnitandInformationUnitenums for unit metadataBitRatefor transfer rates stored internally as bits per secondBitRateUnitfor bit/byte-per-second labels and conversion factors
Installation
composer require componenta/byte
Related Packages
This package is standalone.
| Package | Why it may be used nearby |
|---|---|
componenta/duration |
Transfer-time calculations pair naturally with typed durations. |
componenta/validation |
Can validate user input before creating Byte or BitRate. |
componenta/config |
Can store upload or bandwidth limits that are later converted to value objects. |
Byte Usage
use Componenta\Stdlib\Byte; $size = Byte::mb(1.5); (string) $size; // "1.5 MB" $size->toBits(); // 12582912.0 $size->to('kB', 2); // formatted string $size->getValue('MB'); // numeric value in megabytes
Byte accepts numeric values and human-readable strings:
$a = Byte::fromHumanReadable('10 MB'); $b = Byte::fromBits(8_000); $c = Byte::from(2, 'GB');
Byte Operations
Byte supports:
- comparison:
compare,equalTo,lessThan,greaterThan, range checks - arithmetic:
increment,decrement,multiply,divide,modulo,abs - aggregation:
sum,average,maximum,minimum - transfer estimates:
getTransferTime,getFormattedTransferTime
Range generation is capped internally to avoid accidental huge allocations.
Bit Rate Usage
use Componenta\Stdlib\BitRate; use Componenta\Stdlib\Byte; $rate = BitRate::mbps(80); $seconds = Byte::mb(10)->getTransferTime($rate); $amount = $rate->calculateTransferAmount(1);
BitRate supports both bit and byte transfer units:
BitRate::fromHumanReadable('80 Mbps'); BitRate::fromHumanReadable('10 MBps'); BitRate::kilobytesPerSecond(512);
Unit Rules
Byteuses binary storage units based on 1024.BitRateuses decimal transfer units based on 1000.BitRatestores its internal value as bits per second.MbpsandMBpsare different labels: megabits per second vs megabytes per second.
Serialization
BitRate implements JsonSerializable. Byte implements Stringable and exposes explicit conversion methods for numeric values and formatted strings.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-14