PHPackages                             flyokai/amp-csv-reader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. flyokai/amp-csv-reader

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

flyokai/amp-csv-reader
======================

Async csv file reader using amphp

0.1.0(1mo ago)07↓50%MITPHPPHP ^8.1

Since Apr 25Pushed yesterdayCompare

[ Source](https://github.com/flyokai/amp-csv-reader)[ Packagist](https://packagist.org/packages/flyokai/amp-csv-reader)[ RSS](/packages/flyokai-amp-csv-reader/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

flyokai/amp-csv-reader
======================

[](#flyokaiamp-csv-reader)

> User docs → [`README.md`](README.md) · Agent quick-ref → [`CLAUDE.md`](CLAUDE.md) · Agent deep dive → [`AGENTS.md`](AGENTS.md)

> Async, generator-based CSV streaming for AMPHP 3.x with backpressure-aware row buffering.

Streams a CSV file row by row without buffering the whole file in memory, while staying friendly to the AMPHP cooperative event loop. Multi-line quoted fields are handled correctly.

Features
--------

[](#features)

- `IteratorAggregate` — drop into `foreach`
- Stateful generator parser → `str_getcsv()` for final field interpretation
- Configurable bounded queue for backpressure
- Cancellation support
- `array2csv()` helper for the reverse direction

Installation
------------

[](#installation)

```
composer require flyokai/amp-csv-reader
```

Quick start
-----------

[](#quick-start)

```
use Amp\File;
use Flyokai\AmpCsvReader\CsvReader;

$stream = File\openFile('data.csv', 'r');
$reader = new CsvReader($stream, bufferSize: 500);

foreach ($reader as $row) {
    // $row is a numeric array — no header handling
}
```

Constructor
-----------

[](#constructor)

```
new CsvReader(
    Amp\ByteStream\ReadableStream $stream,
    int $bufferSize = 0,                 // 0 = unlimited
    string $separator = ',',
    string $enclosure = '"',
    string $escape = "\\",
    ?Amp\Cancellation $stopCancellation = null,
);
```

Lifecycle
---------

[](#lifecycle)

```
ReadableStream → Parser (generator)
    → Buffer accumulation (multi-line quoted fields)
    → consumeBuffer() → str_getcsv()
    → Queue → ConcurrentIterator → foreach

```

1. `getIterator()` lazily creates a `Queue` and schedules `read()` on the event loop
2. `read()` pulls chunks from the stream, feeds the parser
3. `parse()` tracks escape mode for quoted fields, accumulates a row buffer
4. Complete rows flow through `str_getcsv()` and into the queue
5. The consumer iterates via `ConcurrentIterator`

Helpers
-------

[](#helpers)

- `isComplete(): bool` — whether all rows have been parsed
- `onComplete(\Closure $callback): void` — fires when parsing finishes
- `array2csv(array $data, string $delimiter = ',', string $enclosure = '"', string $escape = '\\'): string` — array → CSV (uses `php://memory`)

Gotchas
-------

[](#gotchas)

- **No header handling** — every row is a numeric array. Map columns yourself if you need them by name.
- **Empty rows are dropped** — `consumeBuffer()` silently skips lines that trim to empty.
- **`bufferSize=0` is unlimited** — slow consumers on large files will grow memory unbounded.
- **Single-use** — `getIterator()` is lazy but non-resettable. To re-read the file, open a new stream and a new reader.
- **Cancellation flushes the buffer** — the reader still emits buffered rows after cancellation before completing.

See also
--------

[](#see-also)

- Used by data-import pipelines built on `flyokai/amp-data-pipeline`.

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance96

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

45d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/247743048?v=4)[flyokai](/maintainers/flyokai)[@flyokai](https://github.com/flyokai)

---

Top Contributors

[![flyokai](https://avatars.githubusercontent.com/u/247743048?v=4)](https://github.com/flyokai "flyokai (3 commits)")

### Embed Badge

![Health badge](/badges/flyokai-amp-csv-reader/health.svg)

```
[![Health](https://phpackages.com/badges/flyokai-amp-csv-reader/health.svg)](https://phpackages.com/packages/flyokai-amp-csv-reader)
```

###  Alternatives

[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.4k885.1k21](/packages/danog-madelineproto)[amphp/parallel

Parallel processing component for Amp.

85049.9M89](/packages/amphp-parallel)[amphp/process

A fiber-aware process manager based on Amp and Revolt.

25657.8M64](/packages/amphp-process)[amphp/parallel-functions

Parallel processing made simple.

27910.5M26](/packages/amphp-parallel-functions)[amphp/mysql

Asynchronous MySQL client for PHP based on Amp.

3761.1M33](/packages/amphp-mysql)[phel-lang/phel-lang

Phel is a functional programming language that compiles to PHP

5085.1k16](/packages/phel-lang-phel-lang)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
