Download the PHP package alexandre-daubois/lazy-stream without Composer

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

LazyStream

Minimum PHP Version CI Latest Version License

LazyStream is a pure PHP, zero-dependencies library that provides a convenient way to write lazily to streams using generators. It allows you to write data incrementally to a stream, reducing memory usage and improving performance when dealing with large amounts of data.

Features

Installation

You can install the LazyStream using Composer. Run the following command in your project directory:

Usage

Writing lazily to a stream with LazyStreamWriter

Why using this writer?

The class allows you to write data to a stream incrementally, in small chunks, rather than loading the entire dataset into memory at once. This is especially beneficial when dealing with large amounts of data, as it reduces memory consumption. It also offers:

Configuring LazyStreamWriter behavior

A few options are available to configure how à lazy stream should behave:

The MultiLazyStreamWriter class

The MultiLazyStreamWriter is a core class in the LazyStream library. This class empowers you to write to multiple streams concurrently from any iterator, like a generator. This is particularly beneficial when you need to write large amounts of data to different locations in a memory-efficient manner.

This class is extremely helpful in situations where large amounts of data need to be written to multiple destinations:

Here is a usage example:

The LazyStreamChunkWriter class

The LazyStreamChunkWriter class is a specialized class that allows you to write data to a stream in chunks. The mechanism is pretty different from other writers. Instead of writing data from a generator, you can write data by calling the send() method. This allows to write data in a more controlled and "natural" way without having to worry about generators and iterators.

The LazyStreamChunkWriter ALWAYS append data to the stream, thus the opening mode can not be controlled. This is done to ensure a proper autoclosing behavior. If you need to write data in an empty stream, you should use the LazyStreamWriter class or ensure your stream is empty before sending data.

Here is an example of how to use the LazyStreamChunkWriter class:

Reading lazily a stream with LazyStreamReader

Files are already read lazily by default: when you call fread(), you only fetch the number of bytes you asked for, not more. LazyStreamReader does the same thing, but it also allows you to keep the stream open or not between reading operations.

Why using this reader?

The autoclose feature of the LazyStreamReader class offers several concrete use cases where it can be useful:

By using the autoclose feature, you simplify resource management, facilitate iterative or asynchronous operations, and have better control over memory management when reading data from a stream.

By setting the autoClose option to true when creating a new LazyStreamReader object, you ask to close the stream after each reading operation and open it again when the next reading operation is triggered. You'll be resumed at the same position you were in the stream before closing it.

Usage of third-party libraries with LazyStream

This library also works well with third-party libraries. For example, you can combine it with the google/cloud-storage package to write big files to your buckets without having to worry about memory problems (among other things).

Indeed, Google Cloud Storage package includes a way to register a Google Storage stream wrapper and use it with the gs:// protocol. Here is an example with this library:


All versions of lazy-stream with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
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 alexandre-daubois/lazy-stream contains the following files

Loading the files please wait ....