-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2: zlib inflate on strings, streams can be appended by a filter to i…
…nflate
- Loading branch information
Showing
3 changed files
with
31 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace DMT\XmlParser\Source; | ||
|
||
class GzipStringParser implements Parser | ||
{ | ||
private string $source; | ||
private int $length; | ||
|
||
public function __construct(string $source, int $length = 1024) | ||
{ | ||
$this->source = $source; | ||
$this->length = $length; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function parse(): iterable | ||
{ | ||
$tmp = inflate_init(ZLIB_ENCODING_GZIP); | ||
$chunks = str_split($this->source, $this->length); | ||
|
||
foreach ($chunks as $chunk) { | ||
yield from str_split(inflate_add($tmp, $chunk)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters