codeinc/human-readable-file-size
Convert raw byte values into clean, human-readable file size strings with this lightweight PHP package. Configurable precision, units, and formatting make it easy to show sizes like 1.5 MB anywhere, and it works seamlessly in Laravel or any PHP project.
Architecture fit. This is a single-purpose formatting utility, not a framework-integrated package. There is no evidence of a service provider, facade, config file, or publishable assets — it is essentially one static call that maps bytes to a display string. That means it fits anywhere in a Laravel codebase (controllers, API resources, Blade, queued jobs) with zero architectural coupling and no bootstrap cost. The trade-off is symmetrical: because it integrates so shallowly, it also delivers very little that a 20-line internal helper would not.
Integration feasibility. Composer-installable, MIT-licensed, and framework-version-agnostic. The only real feasibility question is dependency justification, not technical difficulty. Adding a third-party package to satisfy one string-formatting concern is viable but should be a deliberate decision, especially at 5 stars and 0 dependents — there is no ecosystem signal that this implementation is battle-tested.
Technical risk. Blast radius is small: a formatting bug produces a wrong label, not data loss. The more material risks are:
ext-intl. If it does, that is a hard deployment constraint for a trivial formatting concern.A decisive counter-argument to adoption: recent Laravel versions ship Illuminate\Support\Number::fileSize(), which covers the same use case with framework-level support and no additional dependency. Verify against your pinned Laravel version before defaulting to this package.
Key questions.
PHP_INT_MAX handled?ext-intl or any other extension? What are the PHP version constraints?Number::fileSize() in your Laravel version fully replace it?Stack fit. Standard Composer dependency; works with any Laravel version whose PHP constraint satisfies the package. No migration, no config publishing, no queue or cache interaction. Integration cost is measured in minutes.
Migration path. Do not call the package directly from call sites. Introduce a one-file internal adapter (e.g., App\Support\FileSize::format()) that delegates to the package today and can be reimplemented natively tomorrow. This is the single highest-leverage decision here: it caps the cost of reversing the adoption decision at one file plus its test.
Compatibility. Validate the PHP constraint against all environments in the deployment matrix, including CI and any container base images. If ext-intl is required, confirm it is present everywhere before merge — this is the most likely source of a "works locally, fails in prod" incident.
Sequencing.
Number::fileSize() and a hand-rolled reference implementation across a boundary test set (0, 1, 999, 1000, 1023, 1024, 1 MB ± 1, very large values).Recommendation. Treat this as a default-no with a low-cost override. Adopt only if the boundary tests show behavior you actually want and cannot get from Number::fileSize(); otherwise implement the adapter natively and skip the dependency entirely.
Maintenance. Runtime maintenance is effectively zero — pure computation, no I/O, no state. The recurring cost is dependency hygiene: tracking security advisories and PHP version bumps for a package whose upstream is likely dormant. Budget a lightweight annual review, or eliminate the cost by vendoring/forking (feasible in well under an hour given the size).
Support. Community-only, no SLA, low bus factor. Escalation path is "read the source and patch our own copy," which is acceptable precisely because the surface area is tiny. Do not position this as a supported component in any internal platform catalog.
Scaling. Negligible. Formatting is O(1) string work. The only scaling note is discipline: format at the presentation boundary (Blade, API resource, export formatter), not inside loops over large collections or during serialization of bulk payloads. If file sizes are rendered in high-volume listing endpoints, compute once and cache in the DTO rather than re-invoking per render.
Failure modes.
. producing incorrect output in locales expecting ,.ext-intl is absent in one environment.PHP_INT_MAX on 32-bit targets, or silent truncation of large floats.Ramp-up. Minutes for any PHP developer. There is no domain knowledge to acquire — the only onboarding artifact worth writing is a short note in the adapter's docblock documenting the chosen unit convention and rounding rule so future contributors do not silently change display semantics during a refactor. That note is more operationally valuable than the dependency itself.
How can I help you explore Laravel packages today?