kjljon/streamingiterable
最新稳定版本:v1.0.0
Composer 安装命令:
composer require kjljon/streamingiterable
包简介
Convert iteratables into with streams using psr-7 without any other dependencies
README 文档
README
The idea of this package is to make it easier to work with iterable data as streams
Problem it solves
I find myself exporting data to the file system and using flysystem's writeStream. This becomes an issue when you don't have much local storage to write large exports to.
So my first iteration was pretty ugly (but worked), but then I saw what Guzzle's PSR-7 package did with StreamWrapper and using PSR-7 and figured I could refactor my app to use PSR-7.
My second iteration worked, but still assumed the export was a specific file type (csv).
When I had the requirements to stream JSON, I decided to refactor a little again by adding
the ability to add a formatter decorator.
Usage
$iterable = [ ['first' => 'Jim', 'last' => 'Thompson', 'month' => 'April'], ['first' => 'Tim', 'last' => 'Johnson', 'month' => 'December'] ]; $formatter = new KJLJon\StreamingIterable\Formatter\CsvFormatter(); $stream = new KJLJon\StreamingIterable\IterableToReaderStream($iterable, $formatter); $fp = KJLJon\StreamingIterable\StreamWrapper::getResource($stream); //do something with stream (IE: flyweight's writeStream($location, $fp); fpassthru($fp); fclose($fp);
Questions / Comments
Please open an issue and/or pull request
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-18