@@ -11,7 +11,7 @@ such as a list of user records or log entries. CSV is not exactly a new format
11
11
and has been used in a large number of systems for decades. In particular, CSV
12
12
is often used for historical reasons and despite its shortcomings, it is still a
13
13
very common export format for a large number of tools to interface with
14
- spreadsheet processors (such as Exel , Calc etc.). This library provides a simple
14
+ spreadsheet processors (such as Excel , Calc etc.). This library provides a simple
15
15
streaming API to process very large CSV files with thousands or even millions of
16
16
rows efficiently without having to load the whole file into memory at once.
17
17
@@ -40,7 +40,7 @@ rows efficiently without having to load the whole file into memory at once.
40
40
41
41
## Support us
42
42
43
- We invest a lot of time developing, maintaining and updating our awesome
43
+ We invest a lot of time developing, maintaining, and updating our awesome
44
44
open-source projects. You can help us sustain this high-quality of our work by
45
45
[ becoming a sponsor on GitHub] ( https://github.com/sponsors/clue ) . Sponsors get
46
46
numerous benefits in return, see our [ sponsoring page] ( https://github.com/sponsors/clue )
@@ -96,9 +96,9 @@ World!"
96
96
started using some CSV-variant long before this standard was defined.
97
97
98
98
Some applications refer to CSV as Character-Separated Values, simply because
99
- using another delimiter (such as semicolon or tab) is a rather common approach
99
+ using another delimiter (such as a semicolon or tab) is a rather common approach
100
100
to avoid the need to enclose common values in quotes. This is particularly
101
- common for systems in Europe (and elsewhere) that use a comma as decimal separator.
101
+ common for systems in Europe (and elsewhere) that use a comma as a decimal separator.
102
102
103
103
```
104
104
name;comment
@@ -115,7 +115,7 @@ consistently.
115
115
116
116
Despite its shortcomings, CSV is widely used and this is unlikely to change any
117
117
time soon. In particular, CSV is a very common export format for a lot of tools
118
- to interface with spreadsheet processors (such as Exel , Calc etc.). This means
118
+ to interface with spreadsheet processors (such as Excel , Calc etc.). This means
119
119
that CSV is often used for historical reasons and using CSV to store structured
120
120
application data is usually not a good idea nowadays – but exporting to CSV for
121
121
known applications continues to be a very reasonable approach.
@@ -155,12 +155,12 @@ test,1,24
155
155
"hello world",2,48
156
156
```
157
157
``` php
158
- $stdin = new ReadableResourceStream(STDIN);
158
+ $stdin = new React\Stream\ ReadableResourceStream(STDIN);
159
159
160
- $stream = new Decoder($stdin);
160
+ $csv = new Clue\React\Csv\ Decoder($stdin);
161
161
162
- $stream ->on('data', function ($data) {
163
- // data is a parsed element from the CSV stream
162
+ $csv ->on('data', function (array $data) {
163
+ // $ data is a parsed element from the CSV stream
164
164
// line 1: $data = array('test', '1', '24');
165
165
// line 2: $data = array('hello world', '2', '48');
166
166
var_dump($data);
@@ -179,9 +179,9 @@ use a quote enclosure character (`"`) and a backslash escape character (`\`).
179
179
This behavior can be controlled through the optional constructor parameters:
180
180
181
181
``` php
182
- $stream = new Decoder($stdin, ';');
182
+ $csv = new Clue\React\Csv\ Decoder($stdin, ';');
183
183
184
- $stream ->on('data', function ($data) {
184
+ $csv ->on('data', function (array $data) {
185
185
// CSV fields will now be delimited by semicolon
186
186
});
187
187
```
@@ -193,15 +193,15 @@ unreasonably long lines. It accepts an additional argument if you want to change
193
193
this from the default of 64 KiB:
194
194
195
195
``` php
196
- $stream = new Decoder($stdin, ',', '"', '\\', 64 * 1024);
196
+ $csv = new Clue\React\Csv\ Decoder($stdin, ',', '"', '\\', 64 * 1024);
197
197
```
198
198
199
199
If the underlying stream emits an ` error ` event or the plain stream contains
200
200
any data that does not represent a valid CSV stream,
201
201
it will emit an ` error ` event and then ` close ` the input stream:
202
202
203
203
``` php
204
- $stream ->on('error', function (Exception $error) {
204
+ $csv ->on('error', function (Exception $error) {
205
205
// an error occured, stream will close next
206
206
});
207
207
```
@@ -212,7 +212,7 @@ followed by an `end` event on success or an `error` event for
212
212
incomplete/invalid CSV data as above:
213
213
214
214
``` php
215
- $stream ->on('end', function () {
215
+ $csv ->on('end', function () {
216
216
// stream successfully ended, stream will close next
217
217
});
218
218
```
@@ -221,7 +221,7 @@ If either the underlying stream or the `Decoder` is closed, it will forward
221
221
the ` close ` event:
222
222
223
223
``` php
224
- $stream ->on('close', function () {
224
+ $csv ->on('close', function () {
225
225
// stream closed
226
226
// possibly after an "end" event or due to an "error" event
227
227
});
@@ -231,7 +231,7 @@ The `close(): void` method can be used to explicitly close the `Decoder` and
231
231
its underlying stream:
232
232
233
233
``` php
234
- $stream ->close();
234
+ $csv ->close();
235
235
```
236
236
237
237
The ` pipe(WritableStreamInterface $dest, array $options = array(): WritableStreamInterface `
@@ -240,7 +240,7 @@ Please note that the `Decoder` emits decoded/parsed data events, while many
240
240
(most?) writable streams expect only data chunks:
241
241
242
242
``` php
243
- $stream ->pipe($logger);
243
+ $csv ->pipe($logger);
244
244
```
245
245
246
246
For more details, see ReactPHP's
@@ -261,11 +261,11 @@ test,1
261
261
"hello world",2
262
262
```
263
263
``` php
264
- $stdin = new ReadableResourceStream(STDIN);
264
+ $stdin = new React\Stream\ ReadableResourceStream(STDIN);
265
265
266
- $stream = new AssocDecoder($stdin);
266
+ $csv = new Clue\React\Csv\ AssocDecoder($stdin);
267
267
268
- $stream ->on('data', function ($data) {
268
+ $csv ->on('data', function (array $data) {
269
269
// $data is a parsed element from the CSV stream
270
270
// line 1: $data = array('name' => 'test', 'id' => '1');
271
271
// 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
285
285
a ` headers ` event with a list of header names.
286
286
287
287
``` php
288
- $stream ->on('headers', function (array $headers) {
288
+ $csv ->on('headers', function (array $headers) {
289
289
// header line: $headers = array('name', 'id');
290
290
var_dump($headers);
291
291
});
@@ -312,12 +312,12 @@ and accepts its data through the same interface, but handles any data as complet
312
312
CSV elements instead of just chunks of strings:
313
313
314
314
``` php
315
- $stdout = new WritableResourceStream(STDOUT);
315
+ $stdout = new React\Stream\ WritableResourceStream(STDOUT);
316
316
317
- $stream = new Encoder($stdout);
317
+ $csv = new Clue\React\Csv\ Encoder($stdout);
318
318
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));
321
321
```
322
322
```
323
323
test,1,24
@@ -332,9 +332,9 @@ a Unix-style EOL (`\n` or `LF`).
332
332
This behavior can be controlled through the optional constructor parameters:
333
333
334
334
``` php
335
- $stream = new Encoder($stdout, ';');
335
+ $csv = new Clue\React\Csv\ Encoder($stdout, ';');
336
336
337
- $stream ->write(array('hello', 'world'));
337
+ $csv ->write(array('hello', 'world'));
338
338
```
339
339
```
340
340
hello;world
@@ -345,7 +345,7 @@ any data that can not be represented as a valid CSV stream,
345
345
it will emit an ` error ` event and then ` close ` the input stream:
346
346
347
347
``` php
348
- $stream ->on('error', function (Exception $error) {
348
+ $csv ->on('error', function (Exception $error) {
349
349
// an error occured, stream will close next
350
350
});
351
351
```
@@ -354,7 +354,7 @@ If either the underlying stream or the `Encoder` is closed, it will forward
354
354
the ` close ` event:
355
355
356
356
``` php
357
- $stream ->on('close', function () {
357
+ $csv ->on('close', function () {
358
358
// stream closed
359
359
// possibly after an "end" event or due to an "error" event
360
360
});
@@ -364,22 +364,22 @@ The `end(mixed $data = null): void` method can be used to optionally emit
364
364
any final data and then soft-close the ` Encoder ` and its underlying stream:
365
365
366
366
``` php
367
- $stream ->end();
367
+ $csv ->end();
368
368
```
369
369
370
370
The ` close(): void ` method can be used to explicitly close the ` Encoder ` and
371
371
its underlying stream:
372
372
373
373
``` php
374
- $stream ->close();
374
+ $csv ->close();
375
375
```
376
376
377
377
For more details, see ReactPHP's
378
378
[ ` WritableStreamInterface ` ] ( https://github.com/reactphp/stream#writablestreaminterface ) .
379
379
380
380
## Install
381
381
382
- The recommended way to install this library is [ through Composer] ( https://getcomposer.org ) .
382
+ The recommended way to install this library is [ through Composer] ( https://getcomposer.org/ ) .
383
383
[ New to Composer?] ( https://getcomposer.org/doc/00-intro.md )
384
384
385
385
This project follows [ SemVer] ( https://semver.org/ ) .
@@ -394,12 +394,12 @@ See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
394
394
This project aims to run on any platform and thus does not require any PHP
395
395
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
396
396
HHVM.
397
- It's * highly recommended to use the latest supported PHP version PHP 7+ * for this project.
397
+ It's * highly recommended to use the latest supported PHP version* for this project.
398
398
399
399
## Tests
400
400
401
401
To run the test suite, you first need to clone this repo and then install all
402
- dependencies [ through Composer] ( https://getcomposer.org ) :
402
+ dependencies [ through Composer] ( https://getcomposer.org/ ) :
403
403
404
404
``` bash
405
405
$ composer install
@@ -408,7 +408,7 @@ $ composer install
408
408
To run the test suite, go to the project root and run:
409
409
410
410
``` bash
411
- $ php vendor/bin/phpunit
411
+ $ vendor/bin/phpunit
412
412
```
413
413
414
414
## License
0 commit comments