Streaming parsing?
- Dominant language
- PHP
- Stars
- 14
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
It would be really cool if this library supported streaming parsing of a message. One thing I thought of was accepting an fopen resource or Guzzle stream resource as input, and returning an iterator that returns Guzzle stream resources that are just [LimitStreams](https://github.com/guzzle/streams/blob/master/src/LimitStream.php) over the original data. Then the usage could become something like this:
``` php
$parts = new PartIterator(fopen('http://example.com/huge_multipart_body', 'r'));
foreach ($parts as $part) {
var_dump($part['headers']);
while (!$part['content']->eof()) {
echo $part->read(1024);
}
}
```
In order to get an array of parts, you'd need to provide a sort of helper function with the caveat that it loads the entire message into memory (something like this could be on the iterator):
``` php
public function toArray()
{
$parts = [];
foreach ($this as $part) {
$parts[] = ['headers' => $part['headers'], 'content' => (string) $parts['content']);
}
return $parts;
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.