PHP code example of wyrihaximus / react-stream-hash

1. Go to this page and download the library: Download wyrihaximus/react-stream-hash library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wyrihaximus / react-stream-hash example snippets


$algo = 'sha512'; // Change to any desired algo from hash_algos()
$streamToHash = new ThroughStream();
// Constructor accepts a third $key argument in case you want a HMAC hash
$stream = new WritableStreamHash($streamToHash, $algo);
$stream->on('hash', function ($hash, $algo) {
    // Do with what you need the hash for
});
$stream->on('hash_raw', function ($hash, $algo) {
    // Do with what you need the raw hash for
});

// Write to the stream
$stream->write('foo');
$stream->end('bar');

$algo = 'sha512'; // Change to any desired algo from hash_algos()
$streamToHash = new ThroughStream();
// Constructor accepts a third $key argument in case you want a HMAC hash
$stream = new ReadableStreamHash($streamToHash, $algo);
$stream->on('hash', function ($hash, $algo) {
    // Do with what you need the hash for
});
$stream->on('hash_raw', function ($hash, $algo) {
    // Do with what you need the raw hash for
});

// The readable emits data when written to
$streamToHash->write('foo');
$streamToHash->end('bar');