#bittorrent #metainfo #file #torrent

bip_metainfo

Parsing and building of bittorrent metainfo files

18 releases (11 breaking)

Uses old Rust 2015

0.12.0 Nov 15, 2017
0.11.0 Jul 27, 2017
0.10.0 Jun 11, 2017
0.5.0 Dec 31, 2016
0.0.0 Dec 18, 2015

#41 in #torrent

Download history 10/week @ 2024-07-20 12/week @ 2024-07-27 13/week @ 2024-08-03 10/week @ 2024-08-10 7/week @ 2024-08-17 13/week @ 2024-08-24 25/week @ 2024-08-31 16/week @ 2024-09-07 15/week @ 2024-09-14 45/week @ 2024-09-21 27/week @ 2024-09-28 5/week @ 2024-10-05 12/week @ 2024-10-12 6/week @ 2024-10-19 9/week @ 2024-10-26 49/week @ 2024-11-02

76 downloads per month
Used in 5 crates

MIT/Apache

190KB
4K SLoC

Library for parsing and building metainfo files.

Examples

Building and parsing a metainfo file from a directory:

    extern crate bip_metainfo;

    use bip_metainfo::{MetainfoBuilder, Metainfo};

    fn main() {
        let builder = MetainfoBuilder::new()
            .set_created_by(Some("bip_metainfo example"))
            .set_comment(Some("Metainfo File From A File"));

        // Build the file from the crate's src folder
        let bytes = builder.build(1, "src", |progress| {
            // Progress Is A Value Between 0.0 And 1.0
            assert!(progress <= 1.0f64);
        }).unwrap();
        let file = Metainfo::from_bytes(&bytes).unwrap();

        assert_eq!(file.info().directory(), Some("src".as_ref()));
    }

Building and parsing a metainfo file from direct data:

    extern crate bip_metainfo;

    use bip_metainfo::{MetainfoBuilder, Metainfo, DirectAccessor};

    fn main() {
        let builder = MetainfoBuilder::new()
            .set_created_by(Some("bip_metainfo example"))
            .set_comment(Some("Metainfo File From A File"));

        let file_name = "FileName.txt";
        let file_data = b"This is our file data, it is already in memory!!!";
        let accessor = DirectAccessor::new(file_name, file_data);

        // Build the file from some data that is already in memory
        let bytes = builder.build(1, accessor, |progress| {
            // Progress Is A Value Between 0.0 And 1.0
            assert!(progress <= 1.0f64);
        }).unwrap();
        let file = Metainfo::from_bytes(&bytes).unwrap();

        assert_eq!(file.info().directory(), None);
        assert_eq!(file.info().files().count(), 1);

        let single_file = file.info().files().next().unwrap();
        assert_eq!(single_file.length() as usize, file_data.len());
        assert_eq!(single_file.path().iter().count(), 1);
        assert_eq!(single_file.path().to_str().unwrap(), file_name);
    }

Dependencies

~7–15MB
~176K SLoC