A PHP library for parsing, formatting, converting, and manipulating byte units in metric and binary systems.
Byte Units is a PHP utility library for parsing, formatting, converting, and manipulating byte units with precision. It handles both metric (1000-byte kilobyte) and binary (1024-byte kilobyte) systems, solving problems of ambiguity and conversion errors when working with file sizes, memory allocation, or any byte-based measurements.
PHP developers working on applications that involve file size calculations, memory management, storage reporting, or data transfer measurements, particularly those needing to handle both SI and binary byte units accurately.
Developers choose Byte Units for its dual-system support with clear suffix differentiation (e.g., kB vs. KiB), flexible parsing and formatting options, and built-in comparison and arithmetic operations that preserve unit systems, reducing manual conversion errors.
Library to parse, format and convert byte units
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports both metric (1000-byte) and binary (1024-byte) units with distinct suffixes (kB vs KiB), eliminating ambiguity in byte representation as shown in parsing examples.
Allows precise customization of output with configurable precision, unit forcing, and separators, evidenced by format strings like 'MB/000000' for six decimal places.
Arithmetic operations (add/remove) preserve the unit system of the receiving object, ensuring consistency—e.g., adding metric to binary keeps the result in binary.
Automatically converts integers and strings to appropriate byte units, simplifying code by allowing direct comparisons like isLessThan('1KiB') without manual conversion.
Only supports byte units (metric and binary), lacking extensibility for other measurement types like time or distance, which restricts its utility in broader applications.
Strict parsing throws exceptions (e.g., ParseException for system mismatches), requiring additional error handling that can complicate code for dynamic inputs.
Requires Composer for installation, which adds setup complexity and may not be ideal for environments with minimal dependencies or legacy PHP setups.
At version 0.5, the library is pre-1.0, implying potential breaking changes and lack of long-term stability guarantees, as noted in the composer.json requirement.