Download the PHP package bermudaphp/byte without Composer
On this page you can find all versions of the php package bermudaphp/byte. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bermudaphp/byte
More information about bermudaphp/byte
Files in bermudaphp/byte
Package byte
Short Description A robust PHP class for working with data size units (bytes, kilobytes, megabytes, etc.)
License MIT
Informations about the package byte
Byte and BitRate Classes
Read this in other languages: Russian
Overview
The library provides PHP classes for working with data sizes (Byte) and data transfer rates (BitRate) with comprehensive functionality for conversion, comparison, arithmetic operations, and human-readable formatting.
Features
- Unit Conversion: Easily convert between different data units (B, kB, MB, GB, TB, PB, EB, ZB, YB)
- Transfer Rate Handling: Work with bit rates in various units (bps, kbps, Mbps, Gbps, etc.)
- Arithmetic Operations: Perform addition, subtraction, multiplication, division, and modulo operations
- Comparison: Compare values with support for both individual and array-based comparisons
- Formatting: Format values as human-readable strings with multi-language support
- Range Operations: Create ranges of values, find min/max, calculate averages
- Transfer Time Calculation: Estimate data transfer times based on bandwidth
- Internationalization: Format time durations in multiple languages
Installation
You can install the package via composer:
Usage
Byte Class
Creating Byte Instances
There are multiple ways to create a Byte
instance:
Converting to Different Units
Comparison Operations
The class supports both single-value and multi-value comparisons with two modes:
MODE_ALL
: Returns true only if the condition is true for all valuesMODE_ANY
: Returns true if the condition is true for at least one value
Arithmetic Operations
Static Operations on Collections
BitRate Class
Creating BitRate Instances
Converting Between Units
Comparison Operations
Arithmetic Operations
Transfer Calculations
Static Operations on Collections
BitFormatter for Internationalization
The BitFormatter
class provides formatting functionality with multi-language support:
Error Handling
The classes throw exceptions in the following situations:
\InvalidArgumentException
: When parsing invalid string formats or using unsupported units\LogicException
: When attempting to decrement by a value greater than the current value\DivisionByZeroError
: When attempting to divide by zero
License
This package is open-sourced software licensed under the MIT license.