You are here

function hash in Lockr 7.3

Calculate a hash of a Stream

Parameters

StreamInterface $stream Stream to calculate the hash for:

string $algo Hash algorithm (e.g. md5, crc32, etc):

bool $rawOutput Whether or not to use raw output:

Return value

string Returns the hash of the stream

Throws

\RuntimeException on error.

File

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

Namespace

GuzzleHttp\Psr7

Code

function hash(StreamInterface $stream, $algo, $rawOutput = false) {
  $pos = $stream
    ->tell();
  if ($pos > 0) {
    $stream
      ->rewind();
  }
  $ctx = hash_init($algo);
  while (!$stream
    ->eof()) {
    hash_update($ctx, $stream
      ->read(1048576));
  }
  $out = hash_final($ctx, (bool) $rawOutput);
  $stream
    ->seek($pos);
  return $out;
}