public static function Stream::getHash

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

bool|string Returns false on failure or a hash string on success

2 calls to Stream::getHash()
AbstractEntityBodyDecorator::getContentMd5 in drupal/core/vendor/guzzle/http/Guzzle/Http/AbstractEntityBodyDecorator.php
Get an MD5 checksum of the stream's contents
EntityBody::getContentMd5 in drupal/core/vendor/guzzle/http/Guzzle/Http/EntityBody.php
Get an MD5 checksum of the stream's contents

File

drupal/core/vendor/guzzle/stream/Guzzle/Stream/Stream.php, line 98

Class

Stream
PHP stream implementation

Namespace

Guzzle\Stream

Code

public static function getHash(StreamInterface $stream, $algo, $rawOutput = false) {
  $pos = $stream
    ->ftell();
  if (!$stream
    ->seek(0)) {
    return false;
  }
  $ctx = hash_init($algo);
  while ($data = $stream
    ->read(1024)) {
    hash_update($ctx, $data);
  }
  $out = hash_final($ctx, (bool) $rawOutput);
  $stream
    ->seek($pos);
  return $out;
}