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, 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); }
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. |
Info |
Contains directory and checksum data for a torrent file. |
InfoBuilder |
Builder for generating an info dictionary file from some accessor. |
Metainfo |
Contains optional metadata for a torrent file. |
MetainfoBuilder |
Builder for generating a torrent file from some accessor. |
Enums
PieceAccess |
Type of access given for computing (or not) the checksums for torrent files. |
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 |