n11t / hash-file-service

基于文件哈希内容持久化文件的 服务

0.1.0 2018-03-15 16:17 UTC

This package is not auto-updated.

Last update: 2024-09-26 21:31:28 UTC


README

pipeline status coverage report

HashFileService

基于文件哈希内容持久化文件的 服务

示例

使用此服务来持久化内容或文件。

代码

<?php

$calculator = new \N11t\HashFileService\HashCalculator\GenericHashCalculator('sha1');

$directory = sys_get_temp_dir() . '/hash-service';
$service = new \N11t\HashFileService\HashFileService($directory, $calculator);

$content = "Hello World\n";
echo $service->persistByContent($content);
echo PHP_EOL;

$file = sys_get_temp_dir() . '/test.txt';
echo $service->persistByFile($file);
echo PHP_EOL;

$handle = fopen($file, 'rb+');
echo $service->persistByResource($handle);
echo PHP_EOL;

输出

/tmp/hash-service/2e/a47907b71df53d55ff2d8e5d6c0da6e6a39c84
/tmp/hash-service/2e/a47907b71df53d55ff2d8e5d6c0da6e6a39c84
/tmp/hash-service/2e/a47907b71df53d55ff2d8e5d6c0da6e6a39c84