#bittorrent #bencode

lava_torrent

A library for parsing/encoding bencode and .torrent files

14 releases (7 breaking)

Uses old Rust 2015

0.8.1 Aug 4, 2022
0.7.1 Jul 17, 2022
0.7.0 Mar 28, 2022
0.5.0 Apr 14, 2020
0.2.1 May 25, 2018

#147 in Parser implementations

Download history 19/week @ 2022-04-21 102/week @ 2022-04-28 65/week @ 2022-05-05 212/week @ 2022-05-12 72/week @ 2022-05-19 74/week @ 2022-05-26 128/week @ 2022-06-02 26/week @ 2022-06-09 35/week @ 2022-06-16 48/week @ 2022-06-23 20/week @ 2022-06-30 40/week @ 2022-07-07 57/week @ 2022-07-14 62/week @ 2022-07-21 41/week @ 2022-07-28 131/week @ 2022-08-04

308 downloads per month
Used in find-torrent-data

MIT/Apache

265KB
5K SLoC

lava_torrent

crates.io Build Status codecov

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

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

~1.5–2.5MB
~78K SLoC