@@ -136,9 +136,9 @@ as parsed values instead of just chunks of strings:
136136``` php
137137$stdin = new ReadableResourceStream(STDIN);
138138
139- $stream = new Decoder($stdin);
139+ $ndjson = new Decoder($stdin);
140140
141- $stream ->on('data', function ($data) {
141+ $ndjson ->on('data', function ($data) {
142142 // data is a parsed element from the JSON stream
143143 // line 1: $data = (object)array('name' => 'test', 'active' => true);
144144 // line 2: $data = (object)array('name' => 'hello wörld', 'active' => true);
@@ -157,9 +157,9 @@ This means that, by default, JSON objects will be emitted as a `stdClass`.
157157This behavior can be controlled through the optional constructor parameters:
158158
159159``` php
160- $stream = new Decoder($stdin, true);
160+ $ndjson = new Decoder($stdin, true);
161161
162- $stream ->on('data', function ($data) {
162+ $ndjson ->on('data', function ($data) {
163163 // JSON objects will be emitted as assoc arrays now
164164});
165165```
@@ -171,15 +171,15 @@ unreasonably long lines. It accepts an additional argument if you want to change
171171this from the default of 64 KiB:
172172
173173``` php
174- $stream = new Decoder($stdin, false, 512, 0, 64 * 1024);
174+ $ndjson = new Decoder($stdin, false, 512, 0, 64 * 1024);
175175```
176176
177177If the underlying stream emits an ` error ` event or the plain stream contains
178178any data that does not represent a valid NDJson stream,
179179it will emit an ` error ` event and then ` close ` the input stream:
180180
181181``` php
182- $stream ->on('error', function (Exception $error) {
182+ $ndjson ->on('error', function (Exception $error) {
183183 // an error occured, stream will close next
184184});
185185```
@@ -190,7 +190,7 @@ followed by an `end` event on success or an `error` event for
190190incomplete/invalid JSON data as above:
191191
192192``` php
193- $stream ->on('end', function () {
193+ $ndjson ->on('end', function () {
194194 // stream successfully ended, stream will close next
195195});
196196```
@@ -199,7 +199,7 @@ If either the underlying stream or the `Decoder` is closed, it will forward
199199the ` close ` event:
200200
201201``` php
202- $stream ->on('close', function () {
202+ $ndjson ->on('close', function () {
203203 // stream closed
204204 // possibly after an "end" event or due to an "error" event
205205});
@@ -209,7 +209,7 @@ The `close(): void` method can be used to explicitly close the `Decoder` and
209209its underlying stream:
210210
211211``` php
212- $stream ->close();
212+ $ndjson ->close();
213213```
214214
215215The ` pipe(WritableStreamInterface $dest, array $options = array(): WritableStreamInterface `
@@ -218,7 +218,7 @@ Please note that the `Decoder` emits decoded/parsed data events, while many
218218(most?) writable streams expect only data chunks:
219219
220220``` php
221- $stream ->pipe($logger);
221+ $ndjson ->pipe($logger);
222222```
223223
224224For more details, see ReactPHP's
@@ -236,10 +236,10 @@ JSON elements instead of just chunks of strings:
236236``` php
237237$stdout = new WritableResourceStream(STDOUT);
238238
239- $stream = new Encoder($stdout);
239+ $ndjson = new Encoder($stdout);
240240
241- $stream ->write(array('name' => 'test', 'active' => true));
242- $stream ->write(array('name' => 'hello wörld', 'active' => true));
241+ $ndjson ->write(array('name' => 'test', 'active' => true));
242+ $ndjson ->write(array('name' => 'hello wörld', 'active' => true));
243243```
244244```
245245{"name":"test","active":true}
@@ -252,9 +252,9 @@ This means that, by default, unicode characters will be escaped in the output.
252252This behavior can be controlled through the optional constructor parameters:
253253
254254``` php
255- $stream = new Encoder($stdout, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
255+ $ndjson = new Encoder($stdout, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
256256
257- $stream ->write('hello wörld');
257+ $ndjson ->write('hello wörld');
258258```
259259```
260260"hello wörld"
@@ -268,7 +268,7 @@ any data that can not be represented as a valid NDJSON stream,
268268it will emit an ` error ` event and then ` close ` the input stream:
269269
270270``` php
271- $stream ->on('error', function (Exception $error) {
271+ $ndjson ->on('error', function (Exception $error) {
272272 // an error occured, stream will close next
273273});
274274```
@@ -277,7 +277,7 @@ If either the underlying stream or the `Encoder` is closed, it will forward
277277the ` close ` event:
278278
279279``` php
280- $stream ->on('close', function () {
280+ $ndjson ->on('close', function () {
281281 // stream closed
282282 // possibly after an "end" event or due to an "error" event
283283});
@@ -287,14 +287,14 @@ The `end(mixed $data = null): void` method can be used to optionally emit
287287any final data and then soft-close the ` Encoder ` and its underlying stream:
288288
289289``` php
290- $stream ->end();
290+ $ndjson ->end();
291291```
292292
293293The ` close(): void ` method can be used to explicitly close the ` Encoder ` and
294294its underlying stream:
295295
296296``` php
297- $stream ->close();
297+ $ndjson ->close();
298298```
299299
300300For more details, see ReactPHP's
0 commit comments