Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Read And Write Binary Stream Package

Binary Stream Packager - a tools to handle binary data or stream

  • Manual

    • Write Stream Method
      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
       $write->setBinaryModel(BinaryCode::LITTLE_ENDIAN | BinaryCode::BIG_ENDIAN);
      1. the default write flag to store file is FILE_BINARY you can use method store to change it
         $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

composer require eouna/pack-binary

to install this package

About

use to read or write binary files / binary data stream

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages