/** * Calculate a hash of a Stream * * @param StreamInterface $stream Stream to calculate the hash for * @param string $algo Hash algorithm (e.g. md5, crc32, etc) * @param bool $rawOutput Whether or not to use raw output * * @return bool|string Returns false on failure or a hash string on success */ public static function getHash(StreamInterface $stream, $algo, $rawOutput = false) { $pos = $stream->ftell(); if (!$stream->seek(0)) { return false; } $ctx = hash_init($algo); while (!$stream->feof()) { hash_update($ctx, $stream->read(8192)); } $out = hash_final($ctx, (bool) $rawOutput); $stream->seek($pos); return $out; }
/** * Process response headers * * @param StreamInterface $stream */ protected function processResponseHeaders(StreamInterface $stream) { // Set the size on the stream if it was returned in the response foreach ($this->lastResponseHeaders as $header) { if (stripos($header, 'Content-Length:') === 0) { $stream->setSize(trim(substr($header, 15))); } } }