Download the PHP package amphp/byte-stream without Composer

On this page you can find all versions of the php package amphp/byte-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 byte-stream

amphp/byte-stream

AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind. amphp/byte-stream specifically provides a stream abstraction to ease working with various byte streams.

Installation

This package can be installed as a Composer dependency.

Requirements

This package requires PHP 8.1 or later.

Usage

Streams are an abstraction over ordered sequences of bytes. This package provides the fundamental interfaces ReadableStream and WritableStream.

Note Previous versions used the terms InputStream and OutputStream, but these terms can be confusing depending on the use case.

ReadableStream

ReadableStream offers a primary method: read(). It returns a string or null. null indicates that the stream has ended.

The following example shows a ReadableStream consumption that buffers the complete stream contents.

Note Amp\ByteStream\buffer($stream) can be used instead, but we'd like to demonstrate manual consumption here.

This package offers some basic implementations, other libraries might provide even more implementations, such as amphp/socket.

Payload

Payload implements ReadableStream while also providing a buffer() method for buffering the entire contents. This allows consuming a message either in chunks (streaming) or consume everything at once (buffering). When the object is destructed, any remaining data in the stream is automatically consumed and discarded. This class is useful for small payloads or when the entire contents of a stream is needed before any processing can be done.

Buffering

Buffering a complete readable stream can be accomplished using the buffer() method.

Streaming

Sometimes it's useful / possible to consume a payload in chunks rather than first buffering it completely, e.g. streaming a large HTTP response body directly to disk.

ReadableBuffer

An ReadableBuffer allows creating a ReadableStream from a single known string chunk. This is helpful if the complete stream contents are already known.

It also allows creating a stream without any chunks by passing null as chunk / omitting the constructor argument:

ReadableIterableStream

ReadableIterableStream allows converting an iterable that yields strings into a ReadableStream:

ReadableResourceStream

This package abstracts PHP's stream resources with ReadableResourceStream and WritableResourceStream. They automatically set the passed resource to non-blocking mode and allow reading and writing like any other ReadableStream / WritableStream. They also handle backpressure automatically by disabling the read watcher in case there's no read request and only activate a writability watcher if the underlying write buffer is already full, which makes them very efficient.

DecompressingReadableStream

This package implements compression based on Zlib. CompressingWritableStream can be used for compression, while DecompressingReadableStream can be used for decompression. Both can simply wrap an existing stream to apply them. Both accept an $encoding and $options parameter in their constructor.

See also: ./examples/gzip-decompress.php

WritableStream

WritableStream offers two primary methods: write() and end().

WritableStream::write

write() writes the given string to the stream. Waiting for completion allows writing only as fast as the underlying stream can write and potentially send over a network. TCP streams will return immediately as long as the write buffer isn't full.

The writing order is always ensured, even if the writer doesn't wait for completion before issuing another write.

WritableStream::end

end() marks the stream as ended. TCP streams might close the underlying stream for writing, but MUST NOT close it. Instead, all resources should be freed and actual resource handles be closed by PHP's garbage collection process.

The following example uses the previous example to read from a stream and writes all data to a WritableStream:

Note Amp\ByteStream\pipe($readableStream, $writableStream) can be used instead, but we'd like to demonstrate manual consumption / writing here.

This package offers some basic implementations, other libraries might provide even more implementations, such as amphp/socket.

WritableResourceStream

This package abstracts PHP's stream resources with ReadableResourceStream and WritableResourceStream. They automatically set the passed resource to non-blocking mode and allow reading and writing like any other ReadableStream / WritableStream. They also handle backpressure automatically by disabling the read watcher in case there's no read request and only activate a writability watcher if the underlying write buffer is already full, which makes them very efficient.

CompressingWritableStream

This package implements compression based on Zlib. CompressingWritableStream can be used for compression, while DecompressingReadableStream can be used for decompression. Both can simply wrap an existing stream to apply them. Both accept an $encoding and $options parameter in their constructor.

See also: ./examples/gzip-compress.php

Versioning

amphp/byte-stream follows the semver semantic versioning specification like all other amphp packages.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see LICENSE for more information.


All versions of byte-stream with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
amphp/amp Version ^2
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 amphp/byte-stream contains the following files

Loading the files please wait ....