ramazancetinkaya/byte-formatter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ramazancetinkaya/byte-formatter

Composer 安装命令:

composer require ramazancetinkaya/byte-formatter

包简介

A modern PHP library for formatting and parsing byte values with precision and flexibility.

README 文档

README

PHP Version Packagist Downloads License Stars Issues

Byte Formatter is your go-to PHP library for converting bytes into human-readable strings and vice versa. Built with modern PHP 8 features, it’s fast, reliable, and developer-friendly—making your life just that little bit easier when handling data sizes.

Report a Bug · New Pull Request

⭐ Show Your Support

If you like this project, give it a ⭐ and share it with your network!

🚀 Features

  • 🧠 Smart Formatting: Converts bytes to formats like 10 KiB or 10 KB.
  • 🔄 Two-Way Conversion: Parse size strings like 1.5 MB into bytes.
  • 🎛️ Customizable Precision: Fine-tune decimal places in formatted outputs.
  • ⚙️ Binary & Decimal Prefixes: Switch between 1024 (binary) and 1000 (decimal) systems.
  • 💪 Error Resilient: Robust validation and descriptive error handling.
  • 📦 Lightweight & Dependency-Free: No external dependencies—just clean, reliable PHP.

📦 Installation

You can install the ByteFormatter library using Composer. Run the following command in your terminal:

composer require ramazancetinkaya/byte-formatter

Alternatively, download the source code and include it in your project manually.

Requirements

  • PHP 8.0 or higher.
  • No additional dependencies.

📖 Usage Examples

1. Basic Formatting

require 'vendor/autoload.php';

use ramazancetinkaya\ByteFormatter;

$formatter = new ByteFormatter(true, 2); // Binary prefixes, 2 decimal places

echo $formatter->formatBytes(10240); // Output: "10 KiB"

2. Parse Human-Readable Strings

require 'vendor/autoload.php';

use ramazancetinkaya\ByteFormatter;

$formatter = new ByteFormatter();

$bytes = $formatter->parseSize("1.5 MiB");

echo $bytes; // Output: 1572864

3. Convert Byte Sizes Between Prefix Systems

require 'vendor/autoload.php';

use ramazancetinkaya\ByteFormatter;

$formatter = new ByteFormatter();

echo $formatter->convert(10240, false); // Output: "10 KB" (Decimal prefix)

⚙ Configuration

Option Description Default
useBinaryPrefix Use binary prefixes (1024-based) or decimal (1000) true
precision Number of decimal places for formatted output 2

📖 Documentation

Public Methods

Method Description
formatBytes() Formats a byte size into a human-readable string.
parseSize() Parses a human-readable size string into bytes.
convert() Converts a size between binary and decimal prefix systems or to a specific unit.

📂 Project Structure

src/
├── ByteFormatter.php
composer.json
README.md

🛡 Security

This library is designed with security in mind. Input validation and error handling are implemented to prevent misuse. For vulnerabilities, please open an issue.

🤝 Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.

ramazancetinkaya/byte-formatter 适用场景与选型建议

ramazancetinkaya/byte-formatter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.9k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2023 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「decimal」 「binary」 「php-library」 「data-formatting」 「byte-formatter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ramazancetinkaya/byte-formatter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ramazancetinkaya/byte-formatter 我们能提供哪些服务?
定制开发 / 二次开发

基于 ramazancetinkaya/byte-formatter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-29