# Binary-Stream **Repository Path**: eouna/Binary-Stream ## Basic Information - **Project Name**: Binary-Stream - **Description**: PHP二进制工具包 用于处理二进制流或二进制数据包 - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2020-07-17 - **Last Updated**: 2025-04-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### PHP Read And Write Binary Stream Package Binary Stream Packager - a tools to handle binary data or stream - #### [中文版](https://github.com/eouna/pack-binary/blob/master/README_CN.md) - #### Manual - ##### Write Stream Method ````php use BinaryStream\BinaryWriter; $writer = new BinaryWriter(); $writer->writeUTFString( str_repeat("It`s long string,", 200) ); $writer->writeUTFString(""); $writer->writeInt32(-90); $writer->writeDouble(800); $writer->writeFloat(3.88511321334343434324443324321); $writer->writeDouble(148.3243413243132134343213244313132); $writer->writeChar("s"); $byteWriter = new ByteWriter(); $byteWriter->writeByte(120); $byteWriter->writeInt16ToByte(65530); $byteWriter->writeInt32ToByte(1526456146); $writer->writeByteObject($byteWriter); ```` - **note** 1. the default encode method is BIG ENDIAN you can use method ****setBinaryModel**** to change it ````php $write->setBinaryModel(BinaryCode::LITTLE_ENDIAN | BinaryCode::BIG_ENDIAN); ````` 2. the default write flag to store file is ***FILE_BINARY*** you can use method ****store**** to change it ````php $writer->store(FILE_APPEND); //or $writer->store(FILE_TEXT); //or $writer->store(FILE_APPEND | LOCK_EX); ````` - ##### Read Stream Method ###### the read sequence must match with the write sequence ```` $reader = new BinaryReader($writer->getWriteStream()); $res[] = $reader->readUTFString(); $res[] = $reader->readUTFString(); $res[] = $reader->readInt32(); $res[] = $reader- >readDouble(); $res[] = $reader->readDouble(); $res[] = $reader->readFloat(); $res[] = $reader->readDouble(); $res[] = $reader->readChar(); $byteReader = $reader->readByByteReader(); $res[] = $byteReader->readByte(); $res[] = $byteReader->readBytesToShort(); $res[] = $byteReader->readByteToInt32(); ```` - #### How To Use It > use
style="fontsize:16px;color:#156b39;background-color:#2e2e2e">***composer > require eouna/pack-binary***
to install this package