Skip to content

Commit f51216f

Browse files
committed
Rename $stream to $ndjson in documentation
1 parent e4b9b46 commit f51216f

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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`.
157157
This 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
171171
this 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

177177
If the underlying stream emits an `error` event or the plain stream contains
178178
any data that does not represent a valid NDJson stream,
179179
it 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
190190
incomplete/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
199199
the `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
209209
its underlying stream:
210210

211211
```php
212-
$stream->close();
212+
$ndjson->close();
213213
```
214214

215215
The `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

224224
For 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.
252252
This 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,
268268
it 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
277277
the `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
287287
any final data and then soft-close the `Encoder` and its underlying stream:
288288

289289
```php
290-
$stream->end();
290+
$ndjson->end();
291291
```
292292

293293
The `close(): void` method can be used to explicitly close the `Encoder` and
294294
its underlying stream:
295295

296296
```php
297-
$stream->close();
297+
$ndjson->close();
298298
```
299299

300300
For more details, see ReactPHP's

examples/91-benchmark-count.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL;
2525
}
2626

27-
$decoder = new Decoder(new ReadableResourceStream(STDIN), true);
27+
$ndjson = new Decoder(new ReadableResourceStream(STDIN), true);
2828

2929
$count = 0;
30-
$decoder->on('data', function () use (&$count) {
30+
$ndjson->on('data', function () use (&$count) {
3131
++$count;
3232
});
3333

@@ -36,7 +36,7 @@
3636
printf("\r%d records in %0.3fs...", $count, microtime(true) - $start);
3737
});
3838

39-
$decoder->on('close', function () use (&$count, $report, $start) {
39+
$ndjson->on('close', function () use (&$count, $report, $start) {
4040
$now = microtime(true);
4141
Loop::cancelTimer($report);
4242

examples/validate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
$out = new WritableResourceStream(STDOUT);
1616
$info = new WritableResourceStream(STDERR);
1717

18-
$decoder = new Decoder($in);
18+
$ndjson = new Decoder($in);
1919
$encoder = new Encoder($out);
20-
$decoder->pipe($encoder);
20+
$ndjson->pipe($encoder);
2121

22-
$decoder->on('error', function (Exception $e) use ($info, &$exit) {
22+
$ndjson->on('error', function (Exception $e) use ($info, &$exit) {
2323
$info->write('ERROR: ' . $e->getMessage() . PHP_EOL);
2424
$exit = 1;
2525
});

0 commit comments

Comments
 (0)