pub struct Metainfo { /* private fields */ }Expand description
Owned, validated metainfo inspection object.
Input bytes are copied so this value does not borrow its source. The exact
original bytes remain available, while Metainfo::to_bytes and
Metainfo::write_canonical emit a canonical re-encoding.
§Examples
use btpc_core::{Metainfo, TorrentMode};
let bytes = b"d4:infod6:lengthi0e4:name5:empty12:piece lengthi16e6:pieces0:ee";
let torrent = Metainfo::from_bytes(bytes)?;
assert_eq!(torrent.mode(), TorrentMode::V1);
assert_eq!(torrent.name_utf8(), Some("empty"));
assert_eq!(torrent.original_bytes(), bytes);Implementations§
Source§impl Metainfo
impl Metainfo
Sourcepub fn magnet(&self, options: &MagnetOptions) -> String
pub fn magnet(&self, options: &MagnetOptions) -> String
Generates a deterministic magnet URI.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Parses and validates metainfo from bytes, copying the input.
§Errors
Returns a bencode, resource-limit, or protocol validation error.
Sourcepub fn from_bytes_with_options(
bytes: &[u8],
options: ParseOptions,
) -> Result<Self>
pub fn from_bytes_with_options( bytes: &[u8], options: ParseOptions, ) -> Result<Self>
Parses and validates metainfo using caller-provided limits.
§Errors
Returns a bencode, resource-limit, or protocol validation error.
Sourcepub fn from_vec(bytes: Vec<u8>) -> Result<Self>
pub fn from_vec(bytes: Vec<u8>) -> Result<Self>
Parses and validates owned metainfo bytes without copying the input buffer.
§Errors
Returns a bencode, resource-limit, or protocol validation error.
Sourcepub fn from_vec_with_options(
bytes: Vec<u8>,
options: ParseOptions,
) -> Result<Self>
pub fn from_vec_with_options( bytes: Vec<u8>, options: ParseOptions, ) -> Result<Self>
Parses and validates owned metainfo bytes using caller-provided limits.
The returned object retains the supplied buffer as its exact original
representation, including the raw bencoded info slice used for hashes.
§Errors
Returns a bencode, resource-limit, or protocol validation error.
Sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self>
pub fn from_path(path: impl AsRef<Path>) -> Result<Self>
Reads, parses, and validates metainfo from a filesystem path.
§Errors
Returns a contextual I/O error or any error from Metainfo::from_bytes.
Sourcepub fn from_path_with_options(
path: impl AsRef<Path>,
options: ParseOptions,
) -> Result<Self>
pub fn from_path_with_options( path: impl AsRef<Path>, options: ParseOptions, ) -> Result<Self>
Reads, parses, and validates metainfo using caller-provided limits.
Regular files are checked before allocation. The actual read is capped at one byte beyond the configured maximum so growth races and streams are still rejected without unbounded allocation.
§Errors
Returns a contextual I/O, resource-limit, bencode, or validation error.
Sourcepub const fn parse_options(&self) -> ParseOptions
pub const fn parse_options(&self) -> ParseOptions
Returns the resource limits used to load this object.
Sourcepub const fn mode(&self) -> TorrentMode
pub const fn mode(&self) -> TorrentMode
Returns the validated protocol mode.
Sourcepub fn files(&self) -> &[TorrentFile]
pub fn files(&self) -> &[TorrentFile]
Returns payload files.
Sourcepub const fn piece_length(&self) -> u64
pub const fn piece_length(&self) -> u64
Returns the piece length in bytes.
Sourcepub const fn total_length(&self) -> u64
pub const fn total_length(&self) -> u64
Returns total payload bytes.
Sourcepub const fn piece_count(&self) -> u64
pub const fn piece_count(&self) -> u64
Returns the logical piece count for the active representation.
Sourcepub const fn optional_metadata(&self) -> &OptionalMetadata
pub const fn optional_metadata(&self) -> &OptionalMetadata
Returns all validated optional metadata in one lossless owned model.
Sourcepub fn source(&self) -> Option<&[u8]>
pub fn source(&self) -> Option<&[u8]>
Returns raw source bytes when explicitly present in the info dictionary.
Sourcepub fn created_by(&self) -> Option<&[u8]>
pub fn created_by(&self) -> Option<&[u8]>
Returns raw top-level creator bytes when present.
Sourcepub const fn creation_date(&self) -> Option<i64>
pub const fn creation_date(&self) -> Option<i64>
Returns the top-level creation timestamp when representable as i64.
Sourcepub const fn info_hash_v1(&self) -> Option<InfoHashV1>
pub const fn info_hash_v1(&self) -> Option<InfoHashV1>
Returns the v1 info hash when applicable.
Sourcepub const fn info_hash_v2(&self) -> Option<InfoHashV2>
pub const fn info_hash_v2(&self) -> Option<InfoHashV2>
Returns the v2 info hash when applicable.
Sourcepub fn original_bytes(&self) -> &[u8] ⓘ
pub fn original_bytes(&self) -> &[u8] ⓘ
Returns exact input bytes.
Sourcepub fn unknown_fields(&self) -> &[UnknownField]
pub fn unknown_fields(&self) -> &[UnknownField]
Returns unknown top-level extension fields.
Sourcepub fn unknown_field_bytes(&self, field: &UnknownField) -> &[u8] ⓘ
pub fn unknown_field_bytes(&self, field: &UnknownField) -> &[u8] ⓘ
Returns the exact source bytes for an unknown top-level field.
Sourcepub const fn validate(&self) -> &ValidationReport
pub const fn validate(&self) -> &ValidationReport
Returns the successful validation report retained at construction.
Sourcepub fn write_original(&self, writer: &mut impl Write) -> Result<()>
pub fn write_original(&self, writer: &mut impl Write) -> Result<()>
Writes exact original input bytes.
§Errors
Returns an I/O error preserving the writer’s error as its source.