Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Utils.php

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

Utils

Namespace

GuzzleHttp\Psr7

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal