Struct lava_torrent::torrent::v1::Torrent [] [src]

pub struct Torrent {
    pub announce: String,
    pub announce_list: Option<AnnounceList>,
    pub length: Integer,
    pub files: Option<Vec<File>>,
    pub name: String,
    pub piece_length: Integer,
    pub pieces: Vec<Piece>,
    pub extra_fields: Option<Dictionary>,
    pub extra_info_fields: Option<Dictionary>,
}

Everything found in a .torrent file.

Modeled after the specifications in BEP 3 and BEP 12. Unknown/extension fields will be placed in extra_fields (if the unknown fields are found in the info dictionary then they are placed in extra_info_fields). If you need any of those extra fields you would have to parse it yourself.

Fields

URL of the torrent's tracker.

Announce list as defined in BEP 12.

Total torrent size in bytes (i.e. sum of all files' sizes).

If the torrent contains only 1 file then files is None.

If the torrent contains only 1 file then name is the file name. Otherwise it's the suggested root directory's name.

Block size in bytes.

SHA1 hashs of each block.

Top-level fields not defined in BEP 3.

Fields in info not defined in BEP 3.

Methods

impl Torrent
[src]

[src]

Parse bytes and return the extracted Torrent.

If bytes is missing any required field (e.g. info), or if any other error is encountered (e.g. IOError), then Err(error) will be returned.

[src]

Parse the content of the file at path and return the extracted Torrent.

If the file at path is missing any required field (e.g. info), or if any other error is encountered (e.g. IOError), then Err(error) will be returned.

impl Torrent
[src]

[src]

Encode self as bencode and write the result to dst.

[src]

Encode self as bencode and write the result to path.

path must be the path to a file.

"This function will create a file if it does not exist, and will truncate it if it does."

[src]

Encode self as bencode and return the result in a Vec.

impl Torrent
[src]

[src]

Construct the info dict based on the fields of self.

Certain operations on torrents, such as calculating info hashs, require the extracted info dict. This convenience method does that.

Note that the info dict is constructed each time this method is called (i.e. the return value is not cached). If caching is needed then the caller should handle that.

Since self is taken by reference, and the result is returned by value, certain values will be cloned. Please be aware of this overhead.

[src]

Calculate the Torrent's info hash as defined in BEP 3.

Note that the calculated info hash is not cached. So if this method is called multiple times, multiple calculations will be performed. To avoid that, the caller should cache the return value as needed.

Calculate the Torrent's magnet link as defined in BEP 9.

The dn parameter is set to self.name.

Either self.announce or all trackers in self.announce_list will be used, meaning that there might be multiple tr entries. We don't use both because per BEP 12: "If the client is compatible with the multitracker specification, and if the announce-list key is present, the client will ignore the announce key and only use the URLs in announce-list."

The x.pe parameter (for peer addresses) is currently not supported.

[src]

Check if this torrent is private as defined in BEP 27.

Returns true if private maps to a bencode integer 1. Returns false otherwise.

Trait Implementations

impl Clone for Torrent
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Torrent
[src]

[src]

Formats the value using the given formatter. Read more

impl Eq for Torrent
[src]

impl PartialEq for Torrent
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Display for Torrent
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Torrent

impl Sync for Torrent