Download the PHP package talesoft/tale-stream without Composer
On this page you can find all versions of the php package talesoft/tale-stream. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download talesoft/tale-stream
More information about talesoft/tale-stream
Files in talesoft/tale-stream
Package tale-stream
Short Description A basic PSR-7 and PSR-17 compatible stream utility library
License MIT
Homepage http://docs.talesoft.codes/php/tale/stream
Informations about the package tale-stream
Tale Stream
What is Tale Stream?
This is a direct implementation of the PSR-7 Psr\Http\Message\StreamInterface
and
the PSR-17 Psr\Http\Message\StreamFactoryInterface
. It doesn't add any
extra methods, only a few utility stream factories and some useful
iterators for streams.
It acts as a stable streaming library core for full-fledged streaming libraries like socket implementations or filesystem abstractions.
Installation
Usage
Check out the Functions File to see all things this library does.
Stream all the things
The heart is the Tale\Stream
class you can use with the Tale\stream
function. You can pass any resource of type stream
and have a PSR-7
compatible stream for any purpose.
Create a Stream factory for DI containers
File Streams
The filestream works analogous to the
fopen($filename, $mode, $useIncludePath, $context)
function.
Memory Streams
Memory streams only reside in memory and are gone when the execution ended. This is very useful to create streams on the fly wherever you need one. They are always readable and writable.
Temporary Streams
Temporary streams work like memory streams, but at some point they will start swapping data into a file to save memory.
Input Stream
The input stream is a readable file stream on php://input
.
In most cases, this is the raw HTTP request body and useful
for APIs that work with structured data formats.
Output Stream
The output stream is a writable file stream on php://output
.
This is mostly the output content that is sent to the browser.
STDIN Stream
The standard input stream is a readable file stream on php://stdin
.
This is e.g. content from a piped command.
STDERR Stream
The standard error stream is a writable file stream on php://stderr
.
This is mostly used for output of errors in console commands.
STDOUT Stream
The standard output stream is a writable file stream on php://stdout
.
This is mostly console command output.
Null Stream
The null-stream does nothing. It only implements the interfaces. Useful to avoid defensive null checks on optional dependencies, to suppress things and for testing.
Read streams with iterators
The ReadIterator will read a stream chunk-by-chunk
(default chunk size is 1024). Notice, all the iterators
here work with any PSR-7 stream, not only Tale\Stream
instances.
Iterate lines of a stream
The LineIterator works differently to fgets()
. While the chunk size
on fgets()
limits the length a line can has, the LineIterator will
just wait for the actual end of the line and doesn't care about
the chunk size.
Split streams by delimiters
The SplitIterator is the reason why the LineIterator can work like it does. It can split streams by any delimiter of any length and doesn't care about the chunk size of the internal reader.
Write to streams with iterators
The WriteIterator is a utility to write iterables to streams easily.
Pipe streams
The ReadIterator and WriteIterator combined provide a solid way to pipe streams efficiently.