Skip to content

Commit 60d453d

Browse files
committed
Add dedicated chapters for using and creating streams
1 parent 4a6c128 commit 60d453d

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ descriptor based implementation with an in-memory write buffer.
1313

1414
**Table of contents**
1515

16-
* [API](#api)
16+
* [Stream usage](#stream-usage)
1717
* [ReadableStreamInterface](#readablestreaminterface)
1818
* [data event](#data-event)
1919
* [end event](#end-event)
@@ -34,6 +34,7 @@ descriptor based implementation with an in-memory write buffer.
3434
* [end()](#end)
3535
* [close()](#close-1)
3636
* [DuplexStreamInterface](#duplexstreaminterface)
37+
* [Creating streams](#creating-streams)
3738
* [ReadableResourceStream](#readableresourcestream)
3839
* [WritableResourceStream](#writableresourcestream)
3940
* [DuplexResourceStream](#duplexresourcestream)
@@ -43,7 +44,29 @@ descriptor based implementation with an in-memory write buffer.
4344
* [Tests](#tests)
4445
* [License](#license)
4546

46-
## API
47+
## Stream usage
48+
49+
ReactPHP uses the concept of "streams" throughout its ecosystem to provide a
50+
consistent higher-level abstraction for processing streams of arbitrary data
51+
contents and size.
52+
While a stream itself is a quite low-level concept, it can be used as a powerful
53+
abstraction to build higher-level components and protocols on top.
54+
55+
If you're new to this concept, it helps to think of them as a water pipe:
56+
You can consume water from a source or you can produce water and forward (pipe)
57+
it to any destination (sink).
58+
59+
Similarly, streams can either be
60+
61+
* readable (such as `STDIN` terminal input) or
62+
* writable (such as `STDOUT` terminal output) or
63+
* duplex (both readable *and* writable, such as a TCP/IP connection)
64+
65+
Accordingly, this package defines the following three interfaces
66+
67+
* [`ReadableStreamInterface`](#readablestreaminterface)
68+
* [`WritableStreamInterface`](#writablestreaminterface)
69+
* [`DuplexStreamInterface`](#duplexstreaminterface)
4770

4871
### ReadableStreamInterface
4972

@@ -733,6 +756,18 @@ order to be considered a well-behaving stream.
733756
See also [`ReadableStreamInterface`](#readablestreaminterface) and
734757
[`WritableStreamInterface`](#writablestreaminterface) for more details.
735758

759+
## Creating streams
760+
761+
ReactPHP uses the concept of "streams" throughout its ecosystem, so that
762+
many higher-level consumers of this package only deal with
763+
[stream usage](#stream-usage).
764+
This implies that stream instances are most often created within some
765+
higher-level components and many consumers never actually have to deal with
766+
creating a stream instance.
767+
768+
However, if you are writing a lower-level component or want to create a stream
769+
instance from a stream resource, then the following chapter is for you.
770+
736771
### ReadableResourceStream
737772

738773
The `ReadableResourceStream` is a concrete implementation of the

0 commit comments

Comments
 (0)