#hash #cross-platform #checksum

app dircs

A small cross-platform utility to get the hash of a file or directory

12 releases

0.1.10 Sep 4, 2024
0.1.9 May 23, 2024
0.1.8 Nov 19, 2023
0.1.7 Jun 22, 2023
0.1.4 May 31, 2023

#183 in Command line utilities

Download history 2/week @ 2024-06-28 44/week @ 2024-07-05 65/week @ 2024-07-26 10/week @ 2024-08-02 89/week @ 2024-08-30 23/week @ 2024-09-06 16/week @ 2024-09-13 30/week @ 2024-09-20 23/week @ 2024-09-27 4/week @ 2024-10-04 1/week @ 2024-10-11

60 downloads per month

Apache-2.0

24KB
437 lines

dircs

crates.io link

A small cross-platform utility to get the hash of a file or directory. Comes with a variety of hash functions to choose from.

Note: I mostly wrote this for my own personal use, so there might be a lot of rough edges. Feel free to submit pull requests, feature requests, or bug reports, but my time working on this may be limited.

Installation

Cargo

dircs is on crates.io and can be installed with cargo:

cargo install dircs --locked

As of writing, dircs has been tested to build using Rust 1.70.0.

If you want to disable certain hash functions for whatever reason, you can control this by disabling the appropriate feature for that hash function (see Cargo.toml).

Binaries

As of 0.1.9, binaries are generated on release through CI. These can be accessed in the releases, with the latest releases found here.

To use them, download the appropriate binary for your system and run the binary as needed.

Usage

$ dircs /your/path/here
/your/path/here -> 72ce3b5f2df28051cf7204712fe93de6b7b6d1f8e8fe5972b117a248423c290c

By default, dircs will use BLAKE3 with memmapping disabled, and an automatic level of parallelism.

See more options by running dircs -h.

Supported hash functions

Currently, the following hash functions are supported:

  • BLAKE3 (default)
  • BLAKE2
  • MD5
  • SHA1
  • SHA2 (digest sizes of 256, 384, 512)
  • SHA3 (digest sizes of 256, 384, 512)

How are hashes determined?

For a single file or a directory with just one file, dircs will simply hash the file using the specified hash function, and output the bytes as a hex string.

For a directory with multiple files, we do the following:

  1. For every file, get the hash using the chosen hashing function. This occurs in parallel if possible.
  2. With this generated list of hashes, sort them based on file name.
  3. Feed each hash in this order into the chosen hash function to generate one final hash, which is then output as a hex string.

Thanks

Thanks to:

  • All library authors whose libraries I used.
  • The authors of b3sum, which I referenced a lot.

Dependencies

~6.5MB
~121K SLoC