Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/runfalk/ed2k-rs


https://github.com/runfalk/ed2k-rs

ed2k

Last synced: 3 days ago
JSON representation

Awesome Lists containing this project

README

        

ed2k-rs
=======
An [ed2k](https://en.wikipedia.org/wiki/Ed2k_URI_scheme) hash implementation in
Rust. It supports both current and legacy variants of calculating the ed2k hash.
It does not support AICH hashes.

This crate implements the [digest](https://github.com/RustCrypto/traits/tree/master/digest)
crate's traits for digest algorithms. This means that any changes to this trait
will affect the API of this crate.

Disclaimer
----------
* This is alpha software and the API may change at any time
* Please don't use this for illegal file sharing

Performance
-----------
I have not bothered with super rigorous performance testing. However, on my
computer I have achieved 842 MiB/s in single threaded hashing. `sha256sum` on
the same set of files is 1573 MiB/s (also single threaded).

Example
-------
How to calculate the hash of a file:

```rust
use std::io::Read;
use std::fs::File;
const BUFFER_SIZE: usize = 4096;

// Use ed2k::Ed2kHasher::with_legacy_hashing(true) for legacy variant
let mut hasher = ed2k::Ed2kHasher::new();
let mut file = File::open("/path/to/file")?;

let mut buf = [0u8; BUFFER_SIZE];
loop {
let buf_len = file.read(&mut buf)?;
hasher.update(&buf[..buf_len]);

if buf_len == 0 {
break
}
}

println!("Hash is: {:?}", hasher.finalize());
```

Since file hashing is so common there is a convenience wrapper for this:

```rust
// Use Ed2k::from_path_legacy(...) for legacy variant
let ed2k = Ed2k::from_path("/path/to/file")?;

// The Display trait provides an ed2k link in the format
// ed2k://|file||||/
println!("ed2k URL is {}", ed2k);
```