Crate bip_metainfo [] [src]

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, MetainfoFile};

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

        // Build the file from the crate's src folder
        let bytes = builder.build_as_bytes(1, "src", |progress| {
            // Progress Is A Value Between 0.0 And 1.0
            assert!(progress <= 1.0f64);
        }).unwrap();
        let file = MetainfoFile::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, MetainfoFile, DirectAccessor};

    fn main() {
        let builder = MetainfoBuilder::new()
            .set_created_by("bip_metainfo example")
            .set_comment("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_as_bytes(1, accessor, |progress| {
            // Progress Is A Value Between 0.0 And 1.0
            assert!(progress <= 1.0f64);
        }).unwrap();
        let file = MetainfoFile::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);
    }

Modules

error

Errors for torrent file building and parsing.

iter

Iterators over torrent file information.

Structs

DirectAccessor

Accessor that pulls data in directly from memory.

File

Contains information for a single file.

FileAccessor

Accessor that pulls data in from the file system.

InfoDictionary

Contains files and checksums for the torrent.

MetainfoBuilder

Builder for generating a torrent file from some accessor.

MetainfoFile

Contains optional and required information for the torrent.

Enums

PieceLength

Enumerates settings for piece length for generating a torrent file.

Traits

Accessor

Trait for accessing the data used to construct a torrent file.

IntoAccessor

Trait for types convertible as a Result into some Accessor.

Type Definitions

InfoHash

Bittorrent InfoHash.