[−][src]Struct lava_torrent::torrent::v1::Torrent
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
announce: Option<String>
URL of the torrent's tracker.
announce_list: Option<AnnounceList>
Announce list as defined in BEP 12.
length: Integer
Total torrent size in bytes (i.e. sum of all files' sizes).
files: Option<Vec<File>>
If the torrent contains only 1 file then files
is None
.
name: String
If the torrent contains only 1 file then name
is the file name.
Otherwise it's the suggested root directory's name.
piece_length: Integer
Block size in bytes.
pieces: Vec<Piece>
SHA1 hashs of each block.
extra_fields: Option<Dictionary>
Top-level fields not defined in BEP 3.
extra_info_fields: Option<Dictionary>
Fields in info
not defined in BEP 3.
Methods
impl Torrent
[src]
pub fn read_from_bytes<B>(bytes: B) -> Result<Torrent> where
B: AsRef<[u8]>,
[src]
B: AsRef<[u8]>,
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.
pub fn read_from_file<P>(path: P) -> Result<Torrent> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
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]
pub fn write_into<W>(self, dst: &mut W) -> Result<()> where
W: Write,
[src]
W: Write,
Encode self
as bencode and write the result to dst
.
pub fn write_into_file<P>(self, path: P) -> Result<()> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
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."
Note: it is the client's responsibility to ensure
that all directories in path
actually exist (e.g.
by calling create_dir_all
).
pub fn encode(self) -> Result<Vec<u8>>
[src]
Encode self
as bencode and return the result in a Vec
.
impl Torrent
[src]
pub fn construct_info(&self) -> BencodeElem
[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.
pub fn info_hash(&self) -> String
[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.
pub fn magnet_link(&self) -> String
[src]
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
."
If neither self.announce
nor self.announce_list
is present, the output
won't contain any tr
parameter.
The x.pe
parameter (for peer addresses) is currently not supported.
pub fn is_private(&self) -> bool
[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 Eq for Torrent
[src]
impl Clone for Torrent
[src]
impl PartialEq<Torrent> for Torrent
[src]
impl Debug for Torrent
[src]
impl Display for Torrent
[src]
Auto Trait Implementations
impl Send for Torrent
impl Unpin for Torrent
impl Sync for Torrent
impl UnwindSafe for Torrent
impl RefUnwindSafe for Torrent
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, Dst> ConvAsUtil<Dst> for T
[src]
fn approx(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
[src]
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_by<Scheme>(self) -> Result<Dst, Self::Err> where
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
[src]
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
Scheme: ApproxScheme,
[src]
Scheme: ApproxScheme,
type Err = NoError
The error type produced by a failed conversion.
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
[src]
impl<T> ConvUtil for T
[src]
fn approx_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ApproxInto<Dst, DefaultApprox>,
[src]
Self: ApproxInto<Dst, DefaultApprox>,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err> where
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
[src]
Scheme: ApproxScheme,
Self: ApproxInto<Dst, Scheme>,
fn into_as<Dst>(self) -> Dst where
Self: Into<Dst>,
[src]
Self: Into<Dst>,
fn try_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: TryInto<Dst>,
[src]
Self: TryInto<Dst>,
fn value_as<Dst>(self) -> Result<Dst, Self::Err> where
Self: ValueInto<Dst>,
[src]
Self: ValueInto<Dst>,
impl<Src> ValueFrom<Src> for Src
[src]
type Err = NoError
The error type produced by a failed conversion.
fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>
[src]
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
[src]
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
[src]
impl<Src, Dst> ValueInto<Dst> for Src where
Dst: ValueFrom<Src>,
[src]
Dst: ValueFrom<Src>,
type Err = <Dst as ValueFrom<Src>>::Err
The error type produced by a failed conversion.
fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>
[src]
impl<Src> TryFrom<Src> for Src
[src]
type Err = NoError
The error type produced by a failed conversion.
fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>
[src]
impl<Src, Dst> TryInto<Dst> for Src where
Dst: TryFrom<Src>,
[src]
Dst: TryFrom<Src>,