Download the PHP package coldume/imc-stream without Composer
On this page you can find all versions of the php package coldume/imc-stream. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download coldume/imc-stream
More information about coldume/imc-stream
Files in coldume/imc-stream
Package imc-stream
Short Description Provide an abstract layer for data stream
License MIT
Homepage https://github.com/coldume/imc-stream
Informations about the package imc-stream
ImcStream
This read-only wrapper is an abstract layer between stream open function and any other wrapper. It controls data limit and timeout, gives rewind/seek support to unseekable stream, replaces error reporting with exception handlers, and more!
Depict
Previously:
+----------------------+ +----------------+
| Stream open function | -----> | Any wrapper |
| e.g fopen() | <----- | e.g http://... |
+----------------------+ +----------------+
Now:
+----------------------+ +-------------+ +----------------+
| Stream open function | -----> | imc wrapper | -----> | Any wrapper |
| e.g fopen() | <----- | imc://... | <----- | e.g http://... |
+----------------------+ +-------------+ +----------------+
Installation
Simply add a dependency on coldume/imc-stream to your project's composer.json file:
`
Usage:
Exception Handling
Any supported filesystem function will thorw exception when an error occurs, such as file not found, read error, etc.
``
In addition to the default English exception message, ImcStream can be switched to other languages. You can help with existing translations or to add another language.
``
Seek and Rewind
``
Data Limit and Timeout
These two directives only work on non-local stream.
The stream read function will throw exception if data read exceeds allowalbe size limit or timeout expired.
``
Global URI
This directive only works on non-local stream.
Sometimes, you have to open an URI multiple times:
``
The above operations is inefficient, as it will download the same network resource three times. This problem can be solved by enabling global and seek directive:
``
Once global directive is activated, fclose()
will merely rewind internal
file pointer, let the latter function read from beginning of the file. You have
to call ImcStream::fclose()
to close the internal file pointer.
Resources
-
PHP supported protocols and wrappers.
-
The streamWrapper class.