You are here

function readline in Lockr 7.3

Read a line from the stream up to the maximum allowed buffer length

Parameters

StreamInterface $stream Stream to read from:

int $maxLength Maximum buffer length:

Return value

string

File

vendor/guzzlehttp/psr7/src/functions.php, line 440

Namespace

GuzzleHttp\Psr7

Code

function readline(StreamInterface $stream, $maxLength = null) {
  $buffer = '';
  $size = 0;
  while (!$stream
    ->eof()) {

    // Using a loose equality here to match on '' and false.
    if (null == ($byte = $stream
      ->read(1))) {
      return $buffer;
    }
    $buffer .= $byte;

    // Break when a new line is found or the max length - 1 is reached
    if ($byte === "\n" || ++$size === $maxLength - 1) {
      break;
    }
  }
  return $buffer;
}