bantu/stream-filter-hash

通过哈希函数过滤数据流。

dev-master 2015-03-05 19:22 UTC

This package is not auto-updated.

Last update: 2024-09-10 02:16:03 UTC


README

Travis Build Status Scrutinizer Build Status Code Coverage Scrutinizer Code Quality

安装

通过 composer

$ composer require bantu/stream-filter-hash

用法

使用 HashFilter::appendToWriteStream($stream, $params) 来计算写入 $stream 的所有内容的校验和。$params 参数必须是一个数组,通过 algo 数组键指定要使用的哈希算法(例如 md5sha256)。此外,$params 需要通过 callback 数组键传递一个回调函数或使用 stream 数组键传递一个输出流。

使用Stream的示例

创建一个包含将写入 output.txt 的所有内容的校验和的 output.txt.sha256 文件。

require 'vendor/autoload.php';
$dest = fopen('output.txt', 'w+b');
$hash = fopen('output.txt.md5', 'w+b');
\bantu\StreamFilter\Hash\HashFilter::appendToWriteStream($dest, array(
    'algo' => 'sha256', 'stream' => $hash,
));
fwrite($dest, 'The quick brown fox jumps over the lazy dog');
fclose($dest);
fclose($hash);