pub struct Metainfo { /* private fields */ }
Expand description
Metainfo file (also known as .torrent; see BEP3) describe all data required to find download file/files from peer-to-peer network.
Implementations§
Source§impl Metainfo
impl Metainfo
Sourcepub fn create_file(path: &Path, tracker_addr: &String) -> Result<(), Error>
pub fn create_file(path: &Path, tracker_addr: &String) -> Result<(), Error>
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();
Sourcepub fn from_file(path: &Path) -> Result<Metainfo, Error>
pub fn from_file(path: &Path) -> Result<Metainfo, Error>
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();
Sourcepub fn find_announce(dict: &HashMap<Vec<u8>, BValue>) -> Result<String, Error>
pub fn find_announce(dict: &HashMap<Vec<u8>, BValue>) -> Result<String, Error>
Find value for “announce” key in pre-parsed dictionary (converted to HashMap).
Sourcepub fn find_name(dict: &HashMap<Vec<u8>, BValue>) -> Result<String, Error>
pub fn find_name(dict: &HashMap<Vec<u8>, BValue>) -> Result<String, Error>
Find value for “info:name” key in pre-parsed dictionary (converted to HashMap).
Sourcepub fn find_piece_length(dict: &HashMap<Vec<u8>, BValue>) -> Result<u64, Error>
pub fn find_piece_length(dict: &HashMap<Vec<u8>, BValue>) -> Result<u64, Error>
Find value for “info:piece length” key in pre-parsed dictionary (converted to HashMap).
Sourcepub fn find_pieces(
dict: &HashMap<Vec<u8>, BValue>,
) -> Result<Vec<[u8; 20]>, Error>
pub fn find_pieces( dict: &HashMap<Vec<u8>, BValue>, ) -> Result<Vec<[u8; 20]>, Error>
Find value for “info:pieces” key in pre-parsed dictionary (converted to HashMap).
Sourcepub fn find_length(dict: &HashMap<Vec<u8>, BValue>) -> Option<u64>
pub fn find_length(dict: &HashMap<Vec<u8>, BValue>) -> Option<u64>
Find value for “info:length” key in pre-parsed dictionary (converted to HashMap).
Sourcepub fn find_files(dict: &HashMap<Vec<u8>, BValue>) -> Option<Vec<File>>
pub fn find_files(dict: &HashMap<Vec<u8>, BValue>) -> Option<Vec<File>>
Find value for “info:files” key in pre-parsed dictionary (converted to HashMap).
Sourcepub fn tracker_url(&self) -> &String
pub fn tracker_url(&self) -> &String
Return URL of the tracker
Sourcepub fn pieces_num(&self) -> usize
pub fn pieces_num(&self) -> usize
Return number of SHA-1 hashes.
Sourcepub fn piece_length(&self, piece_index: usize) -> usize
pub fn piece_length(&self, piece_index: usize) -> usize
Return length of specific piece.
Sourcepub fn total_length(&self) -> u64
pub fn total_length(&self) -> u64
Return length of all files described by torrent.
Sourcepub fn file_piece_ranges(&self) -> Vec<(PathBuf, PiecePos, PiecePos)>
pub fn file_piece_ranges(&self) -> Vec<(PathBuf, PiecePos, PiecePos)>
Return vector with information which pieces contain which files.