Download the PHP package wapmorgan/binary-stream without Composer

On this page you can find all versions of the php package wapmorgan/binary-stream. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package binary-stream

BinaryStream

BinaryStream - a handy tool for working with binary data and the best replacement for pack()/unpack() with big list of features.

Composer package Latest Stable Version Total Downloads License Tests

If you are looking for a convenient tool that would allow read and write binary data (whether existing or created by you format), you choose the correct library.

BinaryStream - is a powerful tool for reading and writing binary files. It supports a variety of high-level data types and sometimes lets you forget that you are working with unstructured binary data.

With BinaryStream you can handle network packets, binary files, system protocols and other low-level data.

  1. Features
  2. Manual
  3. Reference
    • Data types
    • API
      • Groups of fields
      • Navigation
      • Auxiliary
      • Configurations
  4. Advanced usage. Writing

Features

Why it's objectively better pack/unpack?

And that's all with PHP 5.3.

Manual

Simple usage

The easiest way to use BinaryStream - this:

This example reads 20 bytes at the beginning of the file as a string.

A more complex example, where the data were located in the following order:

In order to read these data and those that depend on the flags, this example is suitable:

In this example, we read the basic data and the additional, based on the value of flags.

But it is unlikely to be so few data. For added convenience, you can use a group reading function. The previous example can be rewritten as follows:

If you are reading a file in which such groups of data are repeated, you can save a group with a name, and then simply refer to it to read the next data. Let us introduce one more value for data_type: 0b11 - means that this is the last group of data in the file. An example would be:

And now imagine that we have moved to a new file format that is different from the previous one and has a certain mark in the beginning of the file, which will help to distinguish the new from the old format. For example, a new label is a sequence of characters 'A', 'S', 'C'. We need to check the label and if it is present, parse the file according to another scheme, and if it does not, use the old version of the processor. An example to illustrate this:

Installation

Installation via composer:

Reference

Data types

All used data types are presented in the following table:

Type Dimensions Values range Notes
integer 8/16/32/64 bits 0 to 255/65 535/4 294 967 295/9 223 372 036 854 775 807 Also, there's support for non-standard sizes like 24, 40, 48 and 56 bits.
float 32/64 bits 0 to 3.4 x 10^38/1.798 x 10^308 Also, there's support for choosing byte-order when storing a float (unlike pack()).
char 1 byte From 0 to 255 ascii chars -
string [n] of bytes ... -
bit [n] of bits 0 or 1 Also, there's support for combining few consecutive bits in one value.

API

Groups of fields

You can save list of fields definitions with a specific name and use it's name when you need to read the same block few times. A group is defined by group configuration - list of fields, their type and size. To compose group configuration create an array: keys define type and name of fields, values - their size:

So full example of group configuration:

Method Usage Notes
saveGroup($name, array $groupConfiguration) $s->saveGroup('data', ['i:field' => 32, 's:text' => 20]); Create new group with few fields. If group with that name already exists, it replaces original group.
readGroup($name) $data = $s->readGroup('data'); It allows you to read data from pre-saved configuration. To save a group under a new name, use the method saveGroup($name, array $fields)
readGroup(array $groupConfiguration) $data = $s->readGroup(['i:field' => 32, 's:text' => 20]); The fields are listed in the as array in which the keys determine the type and the name of the data fields, and values - dimension (understood as bytes for string and chars, and as bits for everything else). Supported: s, c, i, f and b. If the type is not specified, the field is perceived as a bit (or a few bits). The type and name are separated by a colon (:).

Navigation

Method Usage Notes
go($offset) $stream->go(-128); It goes to the absolute position in the file. If you pass a negative value, the value of the cursor will be set to -$offset bytes from the end of the file.
go($mark) $stream->go('FirstTag'); It moves to the position where the $mark mark has been set.
skip($bytes) $stream->skip(4); Skip the following $bytes bytes.
Method Usage Notes
mark($name) $stream->mark('Tag'); It saves the current cursor position under the $name name.
markOffset($offset, $name) $stream->markOffset(-128, 'FirstTag'); It saves specific position in file under the $name name.
isMarked($name) $stream->isMarked('Tag'); Check whether the $name mark set. Returns true or false.

Auxiliary

Constant Meaning
BinaryStream::BIG Big-endian for integers and floats
BinaryStream::LITTLE Little-endian for integers and float

Configurations

Method Usage Notes
loadConfiguration($file $stream->loadConfiguration('file_format.conf'); Load configuration (byte order and data groups) from an external file. Configuration format - ini. To see an example of such a file, open the conf/mp3.conf file.
saveConfiguration($file) $stream->saveConfiguration('file_format.conf'); Saves the current settings of byte order and all created data groups to an external file in ini-format. This configuration can be later restored from the file with the method loadConfiguration().

Advanced usage. Writing

If you are the one who needs to write data to binary files, you can use additional methods to do so.

Firstly, you need to open a file in one of the modes that allow writing of a file (by default, files are opened in read-only mode). For this when you create an object BinaryStream specify in second argument one of the following modes:

Mode Constant Notes
Creation BinaryStream::CREATE Creates new file. Fails when file already exists.
Recreation BinaryStream::RECREATE Clears all file content and sets cursor at the beginning. Fails when file doesn't exist.
Rewriting BinaryStream::REWRITE Opens file and sets cursor at the beginning. Fails when file doesn't exist.
Appending BinaryStream::APPEND Opens file and sets cursor at the end. Fails when file doesn't exist.

After you have correctly opened the file, you can use the following methods, named by analogy with the other designed for reading.

Data type Method Example Notes
bit writeBit($bit) $s->writeBit(true);
writeBits(array $bits) $s->writeBits([true, false, [2, 2], [4, 10]]); You can combine multiple bits into a single number. To do this, instead of using an array of boolean, in which the first element is the number of bits is used to record the number, and the second element - number.
char writeChar($char) $s->writeChar(32); You can pass a character (string), and the code for this symbol (an integer up to 256).
integer writeInteger($integer, $sizeInBits) $s->writeInteger(256, 32); It supports the following dimensions: 8, 16, 32, 64 bits.
float writeFloat($float, $sizeInBits) $s->writeFloat(123.123, 32); It supports the following dimensions: 32, 64 bits.
string writeString($string) $s->writeString('Abracadabra');

All versions of binary-stream with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wapmorgan/binary-stream contains the following files

Loading the files please wait ....