Skip to content

loophp/path-hasher

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Type Coverage License Donate!

Path Hasher

Description

A library to serialize a filesystem object (file, directory, symlink).

The current implementation focuses on the NAR (Nix ARchive) format used by Nix for deterministic path hashing.

Installation

composer require loophp/path-hasher

Usage

Basic Example

<?php

use Loophp\PathHasher\NAR;

$path = '/path/to/your/file_or_directory';

$hash = (new NAR())->hash($path);

echo $hash; // Outputs the SRI hash (e.g., sha256-<base64>)

The equivalent CLI command is:

nix hash path /path/to/your/file_or_directory

The two outputs will match.

Methods available are:

  • hash: Compute the SRI hash of a given path.
  • extract: Extract a NAR archive to a specified directory.
  • stream: Get a stream generator of the NAR archive.
  • computeHashes: Compute hashes of the NAR archive with different algorithms.

Code quality, tests, benchmarks

Every time changes are introduced into the library, Github runs the tests.

The library has tests written with PHPUnit. Feel free to check them out in the tests directory.

Before each commit, some inspections are executed with GrumPHP; run composer grumphp to check manually.

Contributing

Feel free to contribute by sending pull requests. We are a usually very responsive team and we will help you going through your pull request from the beginning to the end.

For some reasons, if you can't contribute to the code and willing to help, sponsoring is a good, sound and safe way to show us some gratitude for the hours we invested in this package.

Sponsor me on Github and/or any of the contributors.

Changelog

See CHANGELOG.md for a changelog based on git commits.

For more detailed changelogs, please check the release changelogs.

About

Library to serialize a filesystem path

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •