Struct rdest::Metainfo[][src]

pub struct Metainfo { /* fields omitted */ }

Metainfo file (also known as .torrent; see BEP3) describe all data required to find download file/files from peer-to-peer network.

Implementations

impl Metainfo[src]

pub fn create_file(path: &Path, tracker_addr: &String) -> Result<(), Error>[src]

Create new torrent file.

Example

use rdest::Metainfo;
use std::path::Path;

Metainfo::create_file(Path::new("my_file.dat"), &"http://127.0.0.1:8000".to_string()).unwrap();

pub fn from_file(path: &Path) -> Result<Metainfo, Error>[src]

Read metainfo (.torrent) data from file.

Example

use rdest::Metainfo;
use std::path::PathBuf;

let path = PathBuf::from("ubuntu-20.04.2.0-desktop-amd64.iso.torrent");
let torrent = Metainfo::from_file(path.as_path()).unwrap();

pub fn from_bencode(data: &[u8]) -> Result<Metainfo, Error>[src]

Read metainfo (.torrent) data directly from bencoded string.

Example

use rdest::Metainfo;

let torrent = Metainfo::from_bencode(b"d8:announce3:URL4:infod4:name4:NAME12:piece lengthi111e6:pieces20:AAAAABBBBBCCCCCDDDDD6:lengthi222eee").unwrap();

pub fn find_announce(dict: &HashMap<Vec<u8>, BValue>) -> Result<String, Error>[src]

Find value for “announce” key in pre-parsed dictionary (converted to HashMap).

pub fn find_name(dict: &HashMap<Vec<u8>, BValue>) -> Result<String, Error>[src]

Find value for “info:name” key in pre-parsed dictionary (converted to HashMap).

pub fn find_piece_length(dict: &HashMap<Vec<u8>, BValue>) -> Result<u64, Error>[src]

Find value for “info:piece length” key in pre-parsed dictionary (converted to HashMap).

pub fn find_pieces(
    dict: &HashMap<Vec<u8>, BValue>
) -> Result<Vec<[u8; 20]>, Error>
[src]

Find value for “info:pieces” key in pre-parsed dictionary (converted to HashMap).

pub fn find_length(dict: &HashMap<Vec<u8>, BValue>) -> Option<u64>[src]

Find value for “info:length” key in pre-parsed dictionary (converted to HashMap).

pub fn find_files(dict: &HashMap<Vec<u8>, BValue>) -> Option<Vec<File>>[src]

Find value for “info:files” key in pre-parsed dictionary (converted to HashMap).

pub fn tracker_url(&self) -> &String[src]

Return URL of the tracker

pub fn piece(&self, piece_index: usize) -> &[u8; 20][src]

Return SHA-1 hash of specific piece.

pub fn pieces_num(&self) -> usize[src]

Return number of SHA-1 hashes.

pub fn piece_length(&self, piece_index: usize) -> usize[src]

Return length of specific piece.

pub fn total_length(&self) -> u64[src]

Return length of all files described by torrent.

pub fn info_hash(&self) -> &[u8; 20][src]

Return SHA-1 hash of info section.

pub fn file_piece_ranges(&self) -> Vec<(PathBuf, PiecePos, PiecePos)>[src]

Return vector with information which pieces contain which files.

Trait Implementations

impl Clone for Metainfo[src]

impl Debug for Metainfo[src]

impl PartialEq<Metainfo> for Metainfo[src]

impl StructuralPartialEq for Metainfo[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.