amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.
https://amphp.org/byte-stream
MIT License
369 stars 29 forks source link

LineReader custom delimiter #69

Closed userqq closed 4 years ago

userqq commented 4 years ago

Hi. It would be great to have possibility use custom delimiters in LineReader, e.g.

final class LineReader
{
    ...
    public function __construct(InputStream $inputStream, $delimiter = "\n")
    ...
}
$reader = new \Amp\ByteStream\LineReader($stream, "\x0a\x00");
kelunik commented 4 years ago

Looks like a useful addition. However, it needs some special consideration for \rtrim($line, "\r"); which shouldn't be applied in that case. Do you want to provide a PR?

userqq commented 4 years ago

@kelunik Please see draft PR https://github.com/amphp/byte-stream/pull/77