Download the PHP package innmind/io without Composer
On this page you can find all versions of the php package innmind/io. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package io
Short Description High level abstraction for streams and sockets
License MIT
Homepage http://github.com/innmind/io
Informations about the package io
io
High level abstraction on top of innmind/stream
to work with streams in a more functional way.
Installation
Usage
[!NOTE] examples below use
innmind/operating-system
Reading from a stream by chunks
The $chunks
variable is a Innmind\Innmutable\Sequence
containing Innmind\Immutable\Str
values, where each value is of a maximum length of 8192
bytes. Before a value is yielded it will make sure data is available before reading from the stream. If no data is available within 1
second the Sequence
will throw an exception saying it can't read from the stream, if you don't want it to throw replace timeoutAfter()
by watch()
so it will wait as long as it needs to.
Reading from a stream by lines
This is the same as reading by chunks (described above) except that the delimiter is the end of line character \n
.
Reading from a socket with a periodic heartbeat
This example will wait to read a single from the socket /tmp/foo.sock
and it will send a heartbeat
message every second until the expected line is received.
Reading from a stream
This example will:
- open the local socket
/some/socket
- watch the socket to be ready for
1
second before it times out each time it tries to read from it - read chunks of a maximum length of
8192
- use the encoding
ASCII
- call the function passed to
->fold()
each time a chunk is read - it will continue reading from the stream until one of the chunks contains
quit
orthrow
- return a
Maybe<Either<string, list<string>>>
- contains nothing when it failed to read from the stream or it timed out
string
is the value passed toFold::fail()
list<string>
is the value passed toFold::result()
You can think of this fold
operation as a reduce where you can control when to stop iterating by return either Fold::fail()
or Fold::result()
.
All versions of io with dependencies
innmind/immutable Version ~5.2
innmind/stream Version ~4.0
innmind/socket Version ~6.1