Skip to content

Commit 725a6a7

Browse files
committed
Rename $stream to $csv in documentation
1 parent a02acf1 commit 725a6a7

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ test,1,24
157157
```php
158158
$stdin = new ReadableResourceStream(STDIN);
159159

160-
$stream = new Decoder($stdin);
160+
$csv = new Decoder($stdin);
161161

162-
$stream->on('data', function ($data) {
163-
// data is a parsed element from the CSV stream
162+
$csv->on('data', function ($data) {
163+
// $data is a parsed element from the CSV stream
164164
// line 1: $data = array('test', '1', '24');
165165
// line 2: $data = array('hello world', '2', '48');
166166
var_dump($data);
@@ -179,9 +179,9 @@ use a quote enclosure character (`"`) and a backslash escape character (`\`).
179179
This behavior can be controlled through the optional constructor parameters:
180180

181181
```php
182-
$stream = new Decoder($stdin, ';');
182+
$csv = new Decoder($stdin, ';');
183183

184-
$stream->on('data', function ($data) {
184+
$csv->on('data', function ($data) {
185185
// CSV fields will now be delimited by semicolon
186186
});
187187
```
@@ -193,15 +193,15 @@ unreasonably long lines. It accepts an additional argument if you want to change
193193
this from the default of 64 KiB:
194194

195195
```php
196-
$stream = new Decoder($stdin, ',', '"', '\\', 64 * 1024);
196+
$csv = new Decoder($stdin, ',', '"', '\\', 64 * 1024);
197197
```
198198

199199
If the underlying stream emits an `error` event or the plain stream contains
200200
any data that does not represent a valid CSV stream,
201201
it will emit an `error` event and then `close` the input stream:
202202

203203
```php
204-
$stream->on('error', function (Exception $error) {
204+
$csv->on('error', function (Exception $error) {
205205
// an error occured, stream will close next
206206
});
207207
```
@@ -212,7 +212,7 @@ followed by an `end` event on success or an `error` event for
212212
incomplete/invalid CSV data as above:
213213

214214
```php
215-
$stream->on('end', function () {
215+
$csv->on('end', function () {
216216
// stream successfully ended, stream will close next
217217
});
218218
```
@@ -221,7 +221,7 @@ If either the underlying stream or the `Decoder` is closed, it will forward
221221
the `close` event:
222222

223223
```php
224-
$stream->on('close', function () {
224+
$csv->on('close', function () {
225225
// stream closed
226226
// possibly after an "end" event or due to an "error" event
227227
});
@@ -231,7 +231,7 @@ The `close(): void` method can be used to explicitly close the `Decoder` and
231231
its underlying stream:
232232

233233
```php
234-
$stream->close();
234+
$csv->close();
235235
```
236236

237237
The `pipe(WritableStreamInterface $dest, array $options = array(): WritableStreamInterface`
@@ -240,7 +240,7 @@ Please note that the `Decoder` emits decoded/parsed data events, while many
240240
(most?) writable streams expect only data chunks:
241241

242242
```php
243-
$stream->pipe($logger);
243+
$csv->pipe($logger);
244244
```
245245

246246
For more details, see ReactPHP's
@@ -263,9 +263,9 @@ test,1
263263
```php
264264
$stdin = new ReadableResourceStream(STDIN);
265265

266-
$stream = new AssocDecoder($stdin);
266+
$csv = new AssocDecoder($stdin);
267267

268-
$stream->on('data', function ($data) {
268+
$csv->on('data', function ($data) {
269269
// $data is a parsed element from the CSV stream
270270
// line 1: $data = array('name' => 'test', 'id' => '1');
271271
// line 2: $data = array('name' => 'hello world', 'id' => '2');
@@ -285,7 +285,7 @@ assoc arrays. After receiving the name of headers, this class will always emit
285285
a `headers` event with a list of header names.
286286

287287
```php
288-
$stream->on('headers', function (array $headers) {
288+
$csv->on('headers', function (array $headers) {
289289
// header line: $headers = array('name', 'id');
290290
var_dump($headers);
291291
});
@@ -314,10 +314,10 @@ CSV elements instead of just chunks of strings:
314314
```php
315315
$stdout = new WritableResourceStream(STDOUT);
316316

317-
$stream = new Encoder($stdout);
317+
$csv = new Encoder($stdout);
318318

319-
$stream->write(array('test', true, 24));
320-
$stream->write(array('hello world', 2, 48));
319+
$csv->write(array('test', true, 24));
320+
$csv->write(array('hello world', 2, 48));
321321
```
322322
```
323323
test,1,24
@@ -332,9 +332,9 @@ a Unix-style EOL (`\n` or `LF`).
332332
This behavior can be controlled through the optional constructor parameters:
333333

334334
```php
335-
$stream = new Encoder($stdout, ';');
335+
$csv = new Encoder($stdout, ';');
336336

337-
$stream->write(array('hello', 'world'));
337+
$csv->write(array('hello', 'world'));
338338
```
339339
```
340340
hello;world
@@ -345,7 +345,7 @@ any data that can not be represented as a valid CSV stream,
345345
it will emit an `error` event and then `close` the input stream:
346346

347347
```php
348-
$stream->on('error', function (Exception $error) {
348+
$csv->on('error', function (Exception $error) {
349349
// an error occured, stream will close next
350350
});
351351
```
@@ -354,7 +354,7 @@ If either the underlying stream or the `Encoder` is closed, it will forward
354354
the `close` event:
355355

356356
```php
357-
$stream->on('close', function () {
357+
$csv->on('close', function () {
358358
// stream closed
359359
// possibly after an "end" event or due to an "error" event
360360
});
@@ -364,14 +364,14 @@ The `end(mixed $data = null): void` method can be used to optionally emit
364364
any final data and then soft-close the `Encoder` and its underlying stream:
365365

366366
```php
367-
$stream->end();
367+
$csv->end();
368368
```
369369

370370
The `close(): void` method can be used to explicitly close the `Encoder` and
371371
its underlying stream:
372372

373373
```php
374-
$stream->close();
374+
$csv->close();
375375
```
376376

377377
For more details, see ReactPHP's

examples/01-count.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515

1616
$delimiter = isset($argv[1]) ? $argv[1] : ',';
1717

18-
$decoder = new AssocDecoder($in, $delimiter);
18+
$csv = new AssocDecoder($in, $delimiter);
1919

2020
$count = 0;
21-
$decoder->on('data', function () use (&$count) {
21+
$csv->on('data', function () use (&$count) {
2222
++$count;
2323
});
2424

25-
$decoder->on('end', function () use (&$count) {
25+
$csv->on('end', function () use (&$count) {
2626
echo $count . PHP_EOL;
2727
});
2828

29-
$decoder->on('error', function (Exception $e) use (&$count, &$exit, $info) {
29+
$csv->on('error', function (Exception $e) use (&$count, &$exit, $info) {
3030
$info->write('ERROR after record ' . $count . ': ' . $e->getMessage() . PHP_EOL);
3131
$exit = 1;
3232
});

examples/02-validate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
$delimiter = isset($argv[1]) ? $argv[1] : ',';
1919

20-
$decoder = new Decoder($in, $delimiter);
20+
$csv = new Decoder($in, $delimiter);
2121
$encoder = new Encoder($out, $delimiter);
22-
$decoder->pipe($encoder);
22+
$csv->pipe($encoder);
2323

24-
$decoder->on('error', function (Exception $e) use ($info, &$exit) {
24+
$csv->on('error', function (Exception $e) use ($info, &$exit) {
2525
$info->write('ERROR: ' . $e->getMessage() . PHP_EOL);
2626
$exit = 1;
2727
});

examples/11-csv2ndjson.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
$delimiter = isset($argv[1]) ? $argv[1] : ',';
2020

21-
$decoder = new AssocDecoder($in, $delimiter);
21+
$csv = new AssocDecoder($in, $delimiter);
2222

2323
$encoder = new ThroughStream(function ($data) {
2424
$data = \array_filter($data, function ($one) {
@@ -28,9 +28,9 @@
2828
return \json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n";
2929
});
3030

31-
$decoder->pipe($encoder)->pipe($out);
31+
$csv->pipe($encoder)->pipe($out);
3232

33-
$decoder->on('error', function (Exception $e) use ($info, &$exit) {
33+
$csv->on('error', function (Exception $e) use ($info, &$exit) {
3434
$info->write('ERROR: ' . $e->getMessage() . PHP_EOL);
3535
$exit = 1;
3636
});

examples/12-csv2tsv.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
$delimiter = isset($argv[1]) ? $argv[1] : ',';
2020

21-
$decoder = new Decoder($in, $delimiter);
21+
$csv = new Decoder($in, $delimiter);
2222

2323
$encoder = new ThroughStream(function ($data) {
2424
$data = \array_map(function ($value) {
@@ -28,20 +28,20 @@
2828
return \implode("\t", $data) . "\n";
2929
});
3030

31-
$decoder->pipe($encoder)->pipe($out);
31+
$csv->pipe($encoder)->pipe($out);
3232

33-
$decoder->on('error', function (Exception $e) use ($info, &$exit) {
33+
$csv->on('error', function (Exception $e) use ($info, &$exit) {
3434
$info->write('ERROR: ' . $e->getMessage() . PHP_EOL);
3535
$exit = 1;
3636
});
3737

3838
// TSV files MUST include a header line, so complain if CSV input ends without a single line
39-
$decoder->on('end', $empty = function () use ($info, &$exit) {
39+
$csv->on('end', $empty = function () use ($info, &$exit) {
4040
$info->write('ERROR: Empty CSV input' . PHP_EOL);
4141
$exit = 1;
4242
});
43-
$decoder->once('data', function () use ($decoder, $empty) {
44-
$decoder->removeListener('end', $empty);
43+
$csv->once('data', function () use ($csv, $empty) {
44+
$csv->removeListener('end', $empty);
4545
});
4646

4747
$info->write('You can pipe/write a valid CSV stream to STDIN' . PHP_EOL);

examples/91-benchmark-count.php

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

23-
$decoder = new AssocDecoder(new ReadableResourceStream(STDIN));
23+
$csv = new AssocDecoder(new ReadableResourceStream(STDIN));
2424

2525
$count = 0;
26-
$decoder->on('data', function () use (&$count) {
26+
$csv->on('data', function () use (&$count) {
2727
++$count;
2828
});
2929

@@ -32,7 +32,7 @@
3232
printf("\r%d records in %0.3fs...", $count, microtime(true) - $start);
3333
});
3434

35-
$decoder->on('close', function () use (&$count, $report, $start) {
35+
$csv->on('close', function () use (&$count, $report, $start) {
3636
$now = microtime(true);
3737
Loop::cancelTimer($report);
3838

examples/92-benchmark-count-gzip.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
STDERR
3232
));
3333
$process->start();
34-
$decoder = new AssocDecoder($process->stdout);
34+
$csv = new AssocDecoder($process->stdout);
3535

3636
$count = 0;
37-
$decoder->on('data', function () use (&$count) {
37+
$csv->on('data', function () use (&$count) {
3838
++$count;
3939
});
4040

@@ -43,7 +43,7 @@
4343
printf("\r%d records in %0.3fs...", $count, microtime(true) - $start);
4444
});
4545

46-
$decoder->on('close', function () use (&$count, $report, $start) {
46+
$csv->on('close', function () use (&$count, $report, $start) {
4747
$now = microtime(true);
4848
Loop::cancelTimer($report);
4949

0 commit comments

Comments
 (0)