private function detectLineBreak(): void
    {
        $sample = $this->stream->read(10000);

        // Rewind stream if seekable, else decorate the stream so it doesn't have to be rewound.
        if ($this->stream->isSeekable()) {
            $this->stream->rewind();
        } else {
            $this->stream = new AppendStream([
                StreamFactoryDiscovery::find()->createStream($sample),
                $this->stream,
            ]);
        }

        // Adapted from https://stackoverflow.com/questions/11066857
        // Surrounded eols with spaces so they can be split like words
        $sample = preg_replace('/[^\r\n]*(\r\n|\n|\r)/','\1 ', $sample);
        // split words
        $parts = explode(' ', $sample);
        // count number of eol character occurrences
        $arr = array_count_values($parts);
        // choose one with most occurrences
        arsort($arr);
        $eol = key($arr);
        // ensure eol char is valid
        $eol = in_array($eol, ["\n", "\r", "\r\n"], true) ? $eol : "\n";

        $this->eol = $eol;
    }