Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/runfalk/ed2k-rs
https://github.com/runfalk/ed2k-rs
ed2k
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/runfalk/ed2k-rs
- Owner: runfalk
- License: mit
- Created: 2020-10-18T20:33:45.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-28T16:28:05.000Z (about 1 year ago)
- Last Synced: 2024-10-13T09:15:06.850Z (about 1 month ago)
- Topics: ed2k
- Language: Rust
- Homepage:
- Size: 19.5 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 sharingPerformance
-----------
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);
```