withinboredom / bytes
字节之间的转换
v1.1.0
2024-02-25 12:32 UTC
Requires
- php: >=8.3
Requires (Dev)
- laravel/pint: ^1.14
- pestphp/pest: ^2.34
README
此库允许您以近乎原生的方式创建定义数据单元,比较它们,并在它们之间进行转换。
使用此库
composer require withinboredom/bytes
此库很特别!
以下代码是100%有效的
$kb = \Withinboredom\Bytes\Kilobytes(128)->multiply(1000); $mb = \Withinboredom\Bytes\Megabytes(125); $tb = \Withinboredom\Bytes\Terrabytes(1); $arr = [$kb, $mb, $tb]; // sort the array usort($arr, \Withinboredom\Bytes\Bytes::compare(...)); // values with the same units are always triple-equal to each other assert($kb->megabytes() === $mb); // values with the same units are always natively comparable assert($mb < $tb->megabytes()); // you can always expect a certain unit function test(\Withinboredom\Bytes\Megabytes $megabytes): void; // or convert them to your expected unit in your body function test(\Withinboredom\Bytes\DataUnit $size): void; // get base-2 sized values echo $kb->getBinaryValue(); // or si-units echo $kb->getSiValue();