jotaelesalinas/php-data-streams
最新稳定版本:v2.0.0
Composer 安装命令:
composer require jotaelesalinas/php-data-streams
包简介
Read and write huge CSV, JSON, XML and Excel streams in PHP without running out of memory.
关键字:
README 文档
README
[!IMPORTANT]
This is a breaking v2 release and is not compatible with the old
jotaelesalinas/php-rwgen package.
The package name, namespace, and public API have changed.
php-data-streams is a PHP streaming library for reading and writing large CSV, JSON, XML, XLSX, KML, HTTP and database-backed records without loading everything into memory.
It is designed for data pipelines, import/export jobs, CLI tools and integrations where you want small, explicit reader and writer abstractions instead of heavyweight framework-specific layers.
What it solves
- Process large files and responses record by record.
- Keep memory usage predictable while iterating through data.
- Compose simple readers and writers around generators and iterables.
- Reuse a shared contract across multiple formats.
How This Repository Is Organized
This project is a monorepo split into several smaller packages.
That means the repository contains multiple packages in one place, but you do not need to install all of them. Install only the package or packages you actually need.
For example:
- If you only work with CSV files, install the CSV package.
- If you only need JSON Lines, install the JSON package.
- If you want the shared reader and writer interfaces for your own code, install the core package.
Packages
corefor the sharedReaderandWritercontracts.csvfor CSV and TSV readers and writers.jsonfor JSON, JSON arrays and NDJSON / JSON Lines.xmlfor lazy XML readers and streaming XML writers.kmlfor KML output built on XML.pdofor database cursor helpers.httpfor line and page-oriented HTTP streams.excelfor minimal XLSX sheet readers.
Quick Example
use JLSalinas\DataStreams\Csv\CsvReader; $reader = new CsvReader(__DIR__ . '/customers.csv'); foreach ($reader as $customer) { echo $customer['name'] . PHP_EOL; }
Installation
Install the package you need via Composer. For example, to work with CSV files:
composer require jotaelesalinas/php-data-streams-csv
If you want to work with JSON Lines:
composer require jotaelesalinas/php-data-streams-json
If you want to build your own reader or writer and only need the shared interfaces:
composer require jotaelesalinas/php-data-streams-core
You can also install more than one package if your project needs them.
Example Usage
CSV reader
use JLSalinas\DataStreams\Csv\CsvReader; $reader = new CsvReader(__DIR__ . '/customers.csv'); foreach ($reader as $customer) { echo $customer['name'] . PHP_EOL; }
CSV writer
use JLSalinas\DataStreams\Csv\CsvWriter; $writer = new CsvWriter(__DIR__ . '/export.csv'); $writer->write(['name' => 'Ada', 'email' => 'ada@example.com']); $writer->write(['name' => 'Grace', 'email' => 'grace@example.com']); $writer->close();
JSON reader
use JLSalinas\DataStreams\Json\JsonReader; $reader = new JsonReader(__DIR__ . '/events.ndjson'); foreach ($reader as $event) { var_dump($event); }
Typical Use Cases
- CSV/TSV imports and exports.
- JSON Lines ingestion and generation.
- XML feeds and document-to-record transforms.
- XLSX sheet reading in long-running jobs.
- KML generation from geospatial records.
- Streaming database results and HTTP responses.
Project Status
This repository is the home of independently publishable packages. The codebase has been renamed and reorganized around the JLSalinas\DataStreams namespace, and each package README documents its own behavior and usage.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-09