hasherize: Hash digests for files and directories

[ apache, filesystem, hash, library, program ] [ Propose Tags ] [ Report a vulnerability ]

This library can produce a hash for filesystem content, which can be either a file or a directory.

The name of the file or directory is not included in the hash digest. The digest of a directory is based on the names and contents of the files contained therein. No other filesystem metadata (timestamps, permissions, etc.) is included in the digest.


[Skip to Readme]

Modules

  • Hasherize

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.0.0
Change log changelog.md
Dependencies base (>=4.18 && <4.19), base16-bytestring (>=1.0.2 && <1.1), bytestring (>=0.11 && <0.12), cassava (>=0.5 && <0.6), containers (>=0.6.7 && <0.7), cryptohash-sha256 (>=0.11.102 && <0.12), directory (>=1.3.8 && <1.4), envparse (>=0.5 && <0.6), file-io (>=0.1 && <0.2), filepath (>=1.4.100 && <1.5), hasherize, ki (>=1.0 && <1.1), mtl (>=2.3.1 && <2.4), qsem (>=0.1 && <0.2), quaalude (>=0.0 && <0.1), safe-exceptions (>=0.1.7 && <0.2), stm (>=2.5.1 && <2.6), text (>=2.0.2 && <2.1), unfork (>=1.0.0 && <1.1), vector (>=0.12.3 && <0.13) [details]
License Apache-2.0
Author Chris Martin
Maintainer Chris Martin, Julie Moronuki
Category Filesystem, Hash
Home page https://github.com/typeclasses/hasherize
Uploaded by chris_martin at 2023-07-05T00:17:25Z
Distributions
Executables hasherize
Downloads 66 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2023-07-05 [all 2 reports]

Readme for hasherize-0.0.0.0

[back to package description]

Executable

The hasherize executable creates a copy of a directory in which each direct child of the directory has a hasherized name.

For example, suppose the input directory looks like this:

├── favicon.ico
└── fonts
    ├── css
    │   └── fonts.css
    └── fonts
        ├── FiraMono-Bold.woff2
        └── FiraMono-Regular.woff2

The output directory will look something like this:

├── d7555833df923044e820a82a040850268d80ca2a8b4ade4a7ecb1aaa709f503a-favicon.ico
└── b7114fb092b385a4419e4aafa30075ded6fe3232219dcb75f49afbc24bbee39c-fonts
    ├── css
    │   └── fonts.css
    └── fonts
        ├── FiraMono-Bold.woff2
        └── FiraMono-Regular.woff2

Additionally, a CSV file will be generated that maps input names to hashed names:

favicon.ico,d7555833df923044e820a82a040850268d80ca2a8b4ade4a7ecb1aaa709f503a-favicon.ico
fonts,b7114fb092b385a4419e4aafa30075ded6fe3232219dcb75f49afbc24bbee39c-fonts

Parameters

The input and output paths must be specified by environment variables:

  • input-directory - Where to read input from
  • output-directory - Where to write hashed files to
  • output-manifest - Where to put the CSV file

Library

This library provides a function called getHash which computes a hash of a file or directory.

Hasherize.getHash :: (MonadIO m) => OsPath -> m ByteString

Hashing system

A path segment is Unicode text. The hash of a path segment is the SHA-256 digest of its UTF-8 encoding.

A path is a list of path segments. The hash of a path is determined by hashing each segment, concatenating, and taking a SHA-256 digest.

An entry consists of a path and the content of a file. The hash of an entry is determined by hashing the path, hashing the content, concatenating, and taking a SHA-256 digest.

The enumeration of a path is a list of entries.

  • If the path is a file x, its enumeration consists of a single entry, ([], x).
  • If the path is a directory, its enumeration consists of an entry for each file recursively contained within the directory, sorted by path. We assume that the file system contains no directory cycles.

The result returned by the getHash function is produced by enumerating the path, hashing each entry, concatenating, and taking a SHA-256 digest.

The hasherize executable produces a hashed file name by concatenating the hash digest in hexadecimal form, the hyphen character -, and the original file name.