You are here

function HTTP_Response::_readChunked in Flickr API 5

Read a part of response body encoded with chunked Transfer-Encoding

@access private

Return value

string

1 call to HTTP_Response::_readChunked()
HTTP_Response::process in phpFlickr/PEAR/HTTP/Request.php
Processes a HTTP response

File

phpFlickr/PEAR/HTTP/Request.php, line 1344

Class

HTTP_Response
Response class to complement the Request class

Code

function _readChunked() {

  // at start of the next chunk?
  if (0 == $this->_chunkLength) {
    $line = $this->_sock
      ->readLine();
    if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) {
      $this->_chunkLength = hexdec($matches[1]);

      // Chunk with zero length indicates the end
      if (0 == $this->_chunkLength) {
        $this->_sock
          ->readLine();

        // make this an eof()
        return '';
      }
    }
    else {
      return '';
    }
  }
  $data = $this->_sock
    ->read($this->_chunkLength);
  $this->_chunkLength -= HTTP_REQUEST_MBSTRING ? mb_strlen($data, 'iso-8859-1') : strlen($data);
  if (0 == $this->_chunkLength) {
    $this->_sock
      ->readLine();

    // Trailing CRLF
  }
  return $data;
}