function Utils::hash
Calculate a hash of a stream.
This method reads the entire stream to calculate a rolling hash, based on PHP's `hash_init` functions.
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:
Throws
\RuntimeException on error.
File
-
vendor/
guzzlehttp/ psr7/ src/ Utils.php, line 122
Class
Namespace
GuzzleHttp\Psr7Code
public static function hash(StreamInterface $stream, string $algo, bool $rawOutput = false) : string {
$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, $rawOutput);
$stream->seek($pos);
return $out;
}