#bittorrent #bencode #serialization #file #bug #now #maintenance

lava_torrent

A library for parsing/encoding bencode and .torrent files

19 releases (10 breaking)

0.11.1 May 1, 2023
0.10.0 Mar 13, 2023
0.8.1 Aug 4, 2022
0.7.1 Jul 17, 2022
0.2.1 May 25, 2018

#921 in Parser implementations

Download history 39/week @ 2024-08-29 16/week @ 2024-09-05 15/week @ 2024-09-12 53/week @ 2024-09-19 38/week @ 2024-09-26 33/week @ 2024-10-03 29/week @ 2024-10-10 24/week @ 2024-10-17 6/week @ 2024-10-24 66/week @ 2024-10-31 111/week @ 2024-11-07 113/week @ 2024-11-14 71/week @ 2024-11-21 60/week @ 2024-11-28 182/week @ 2024-12-05 137/week @ 2024-12-12

486 downloads per month
Used in 2 crates

MIT/Apache

705KB
5.5K SLoC

lava_torrent

crates.io Build Status codecov

lava_torrent is a library for parsing/encoding/creating bencode and .torrent files.

NOTE: lava_torrent is now in maintenance mode. Bugs will still be fixed, but no new features will be released. If you need something, feel free to fork.

Quick Start

Read a torrent (v1) and print it and its info hash.

use lava_torrent::torrent::v1::Torrent;

let torrent = Torrent::read_from_file("sample.torrent").unwrap();
println!("{}", torrent);
println!("Info hash: {}", torrent.info_hash());

Create a torrent (v1) from files in a directory and save the .torrent file.

use lava_torrent::torrent::v1::TorrentBuilder;

let torrent = TorrentBuilder::new("dir/", 1048576).build().unwrap();
torrent.write_into_file("sample.torrent").unwrap();

Bencode (de)serialization.

use lava_torrent::bencode::BencodeElem;

let bytes = "d4:spam4:eggse".as_bytes();
let dict = BencodeElem::Dictionary([("spam".to_owned(), "eggs".into())].into());

assert_eq!(BencodeElem::from_bytes(bytes).unwrap()[0], dict);
assert_eq!(dict.encode(), bytes);

assert!(dict.write_into_file("/tmp/foo").is_ok());
assert_eq!(BencodeElem::from_file("/tmp/foo").unwrap()[0], dict);

More Info

Please check the documentation.

License: MIT OR Apache-2.0

Dependencies

~2.2–3MB
~62K SLoC