Skip to content

Commit

Permalink
add hash implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Sep 24, 2022
1 parent 2aa24a3 commit 8b3b4f1
Show file tree
Hide file tree
Showing 10 changed files with 5,712 additions and 3 deletions.
66 changes: 64 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![codecov](https://codecov.io/gh/innmind/hash/branch/develop/graph/badge.svg)](https://codecov.io/gh/innmind/hash)
[![Type Coverage](https://shepherd.dev/github/innmind/hash/coverage.svg)](https://shepherd.dev/github/innmind/hash)

Description
This component allows to incrementally compute the hash of a file (or any sequence of strings).

## Installation

Expand All @@ -14,4 +14,66 @@ composer require innmind/hash

## Usage

Todo
```php
use Innmind\OperatingSystem\Factory;
use Innmind\Url\Path;
use Innmind\Hash\{
Hash,
Value,
};
use Innmind\Immutable\Set;

$hashes = Factory::build()
->filesystem()
->mount(Path::of('some-folder/'))
->all()
->map(Hash::sha512->ofFile(...));
$hashes; // Set<Value>
```

Since the computation doesn't rely on the filesystem it can be called on content that is not on the filesystem.

Examples:

```php
use Innmind\OperatingSystem\Factory;
use Innmind\Http\{
Message\Request\Request,
Message\Method,
ProtocolVersion,
};
use Innmind\Url\Url;
use Innmind\Server\Control\Server\Command;
use Innmind\Hash\{
Hash,
Value,
};

$os = Factory::build();
$os
->remote()
->http()(new Request(
Url::of('https://github.com'),
Method::get,
ProtocolVersion::v20,
))
->map(static fn($success) => $success->response()->content())
->map(Hash::sha512->ofContent(...))
->match(
static fn($value) => $value, // Value
static fn() => null, // http call failed
);

$output = $os
->control()
->processes()
->execute(
Command::foreground('git')
->withOption('version'),
)
->output()
->chunks()
->map(static fn($chunk) => $chunk[0]); // to only keep the chunk data

Hash::sha512->ofSequence($output); // Value
```
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"issues": "http://github.com/innmind/hash/issues"
},
"require": {
"php": "~8.1"
"php": "~8.1",
"innmind/immutable": "~4.5",
"innmind/filesystem": "^5.2"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 8b3b4f1

Please sign in to comment.