/** * Emit a range of the message body. * * @param array $range * @param ResponseInterface $response * @param int $maxBufferLength */ private function emitBodyRange(array $range, ResponseInterface $response, $maxBufferLength) { list($unit, $first, $last, $length) = $range; $body = $response->getBody(); if (!$body->isSeekable()) { $contents = $body->getContents(); echo substr($contents, $first, $last - $first + 1); return; } $body = new RelativeStream($body, $first); $body->rewind(); $pos = 0; $length = $last - $first + 1; while (!$body->eof() && $pos < $length) { if ($pos + $maxBufferLength > $length) { echo $body->read($length - $pos); break; } echo $body->read($maxBufferLength); $pos = $body->tell(); } }