承接 amorim778/byte-array-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

amorim778/byte-array-php

最新稳定版本:v1.0.0

Composer 安装命令:

composer require amorim778/byte-array-php

包简介

A modern PHP ByteArray buffer with endian-aware read/write helpers, compression, and conversions.

README 文档

README

Modern, endian-aware byte buffer for PHP inspired by ActionScript's ByteArray and Java's ByteBuffer.

Requirements

  • PHP >= 8.1
  • ext-zlib (for compression helpers)
  • ext-iconv

Installation

composer require byte-array/byte-array

Quick start

<?php

use ByteArray\ByteArray;

require __DIR__ . '/vendor/autoload.php';

$buffer = new ByteArray();
$buffer->writeBoolean(true);
$buffer->writeInt(42);
$buffer->writeUTF('hello');
$buffer->writeDouble(3.14);

$buffer->rewind();

$flag = $buffer->readBoolean();
$number = $buffer->readInt();
$text = $buffer->readUTF();
$pi = $buffer->readDouble();

Features

  • Big- and little-endian reads/writes for common primitives (byte, short, int, float, double).
  • UTF strings with length prefix plus raw UTF byte helpers.
  • Safe bounds checks on every read with clear exceptions.
  • Compression/ decompression (zlib, gzip) with error handling.
  • Conversions to/from Base64 and hexadecimal.
  • File helpers (fromFile, toFile), slicing, duplication, and position helpers (rewind, seek, skip, isEOF).
  • Optional JSON-based serialization (writeJson/readJson) as a safe alternative to PHP serialize.
  • Random byte generation for tokens and seeds.

Endianness

$buffer->setEndian(ByteArray::ENDIAN_LITTLE); // or ByteArray::ENDIAN_BIG

All numeric reads/writes honor the current setting.

Compression helpers

$buffer->compress(ByteArray::COMPRESSION_GZIP);
$buffer->uncompress(ByteArray::COMPRESSION_GZIP);

Exceptions are thrown for unsupported algorithms or failures.

Serialization safety

  • writeObject/readObject mirror the legacy PHP serialize/unserialize flow and must not be used with untrusted data.
  • Prefer the safe alternatives writeJson and readJson when exchanging data externally.

Testing

composer install
composer test

CI

GitHub Actions workflow at .github/workflows/tests.yml runs the PHPUnit suite on PHP 8.1 and 8.2.

License

MIT – see LICENSE.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-06