pub struct Info {
pub name: String,
pub piece_length: u64,
pub pieces: PieceHashes,
pub files: Vec<File>,
pub total_length: u64,
pub private: bool,
pub meta_version: Option<u8>,
}Expand description
The info dictionary from a torrent file.
Contains the core metadata that identifies the torrent content. The hash of this dictionary (in bencode format) is the info hash.
Fields§
§name: StringSuggested name for the file or directory.
piece_length: u64Number of bytes per piece.
pieces: PieceHashesPiece hashes for verification (v1 SHA1, v2 merkle layers, or both).
files: Vec<File>List of files in the torrent.
total_length: u64Total size of all files combined.
private: boolIf true, clients should only use trackers in the metainfo (no DHT/PEX).
meta_version: Option<u8>The meta version field from v2 torrents (2 for BEP-52).
Implementations§
Source§impl Info
impl Info
Sourcepub fn piece_count(&self) -> usize
pub fn piece_count(&self) -> usize
Returns the number of pieces for v1-style piece indexing.
For v1 and hybrid torrents, this returns the piece count. For pure v2 torrents, this calculates based on files and piece length.
Sourcepub fn supports_v1(&self) -> bool
pub fn supports_v1(&self) -> bool
Returns true if this torrent supports v1 protocol.
Sourcepub fn supports_v2(&self) -> bool
pub fn supports_v2(&self) -> bool
Returns true if this torrent supports v2 protocol.
Sourcepub fn get_v1_piece_hash(&self, piece_index: usize) -> Option<[u8; 20]>
pub fn get_v1_piece_hash(&self, piece_index: usize) -> Option<[u8; 20]>
Gets the v1 piece hash for a given piece index.
Returns None for pure v2 torrents or invalid indices.
Sourcepub fn get_v2_piece_hash(
&self,
file_index: usize,
piece_index: usize,
) -> Option<[u8; 32]>
pub fn get_v2_piece_hash( &self, file_index: usize, piece_index: usize, ) -> Option<[u8; 32]>
Gets the v2 piece hash for a given file and piece index within that file.
For v2 torrents, pieces are per-file. This returns the layer hash for the given piece within the specified file.
Sourcepub fn get_file_pieces_root(&self, file_index: usize) -> Option<[u8; 32]>
pub fn get_file_pieces_root(&self, file_index: usize) -> Option<[u8; 32]>
Gets the merkle root (pieces_root) for a file.
Returns None for v1 torrents or if the file has no pieces_root.
Sourcepub fn file_piece_count(&self, file_index: usize) -> usize
pub fn file_piece_count(&self, file_index: usize) -> usize
Returns the number of pieces for a given file (v2 calculation).
For v2 torrents, each file has its own piece space.
Sourcepub fn content_files(&self) -> impl Iterator<Item = &File>
pub fn content_files(&self) -> impl Iterator<Item = &File>
Returns all non-padding files.
Sourcepub fn padding_files(&self) -> impl Iterator<Item = &File>
pub fn padding_files(&self) -> impl Iterator<Item = &File>
Returns all padding files.
Sourcepub fn get_v2_piece_hash_global(
&self,
global_piece_index: usize,
) -> Option<[u8; 32]>
pub fn get_v2_piece_hash_global( &self, global_piece_index: usize, ) -> Option<[u8; 32]>
Gets the v2 piece hash for a global piece index.
For v2 torrents, this maps the global piece index to the correct file and file-local piece index, then returns the layer hash.
For files that fit within a single piece (length <= piece_length), the pieces_root IS the layer hash (no piece layers entry).
Sourcepub fn all_v2_piece_hashes(&self) -> Vec<[u8; 32]>
pub fn all_v2_piece_hashes(&self) -> Vec<[u8; 32]>
Builds a list of all v2 piece hashes in global piece order.
This flattens the per-file piece layers into a single list that can be used for storage verification.