Skip to main content

CreateTorrent

Struct CreateTorrent 

Source
pub struct CreateTorrent { /* private fields */ }
Expand description

Builder for creating .torrent files.

Implementations§

Source§

impl CreateTorrent

Source

pub fn new() -> Self

Create a new torrent builder.

Source

pub fn add_file(self, path: impl AsRef<Path>) -> Self

Add a single file to the torrent.

Source

pub fn add_directory(self, path: impl AsRef<Path>) -> Self

Add all files from a directory recursively.

Source

pub fn set_name(self, name: impl Into<String>) -> Self

Set the torrent name (defaults to the file/directory name).

Source

pub fn set_piece_size(self, bytes: u64) -> Self

Set the piece size in bytes (must be a power of 2, ≥ 16384).

Source

pub fn set_comment(self, s: impl Into<String>) -> Self

Set the comment field.

Source

pub fn set_creator(self, s: impl Into<String>) -> Self

Set the creator field.

Source

pub fn set_creation_date(self, ts: i64) -> Self

Set the creation date (unix timestamp). Defaults to current time.

Source

pub fn set_private(self, private: bool) -> Self

Set the private flag (BEP 27).

Source

pub fn set_source(self, s: impl Into<String>) -> Self

Set the source tag (private tracker identification).

Source

pub fn add_tracker(self, url: impl Into<String>, tier: usize) -> Self

Add a tracker URL at the given tier.

Source

pub fn add_web_seed(self, url: impl Into<String>) -> Self

Add a BEP 19 web seed URL (GetRight-style).

Source

pub fn add_http_seed(self, url: impl Into<String>) -> Self

Add a BEP 17 HTTP seed URL (Hoffman-style).

Source

pub fn add_dht_node(self, host: impl Into<String>, port: u16) -> Self

Add a DHT bootstrap node (BEP 5).

Source

pub fn set_pad_file_limit(self, limit: Option<u64>) -> Self

Set pad file alignment (BEP 47).

  • None — no padding (default)
  • Some(0) — pad after every file
  • Some(n) — pad after files with length > n
Source

pub fn include_mtime(self, enabled: bool) -> Self

Include file modification times in the torrent.

Follow and record symlinks.

Source

pub fn set_hash(self, piece: u32, hash: Id20) -> Self

Set a pre-computed SHA1 hash for a piece (skips disk read during generation).

Source

pub fn set_version(self, version: TorrentVersion) -> Self

Set the torrent version to create.

  • V1Only (default) — standard SHA-1 .torrent (BEP 3)
  • Hybrid — combined v1+v2 with both SHA-1 pieces and SHA-256 Merkle trees (BEP 52)
  • V2Only — pure v2 with SHA-256 Merkle trees only (BEP 52)
Source

pub fn set_ssl_cert(self, cert_pem: Vec<u8>) -> Self

Set the SSL CA certificate (PEM-encoded) for SSL torrent creation. When set, the ssl-cert key is written into the info dict.

Source

pub fn generate(self) -> Result<CreateTorrentResult>

Generate the .torrent file.

§Errors

Returns an error if no files have been added, the piece size is invalid, or file I/O fails during hashing.

Source

pub fn generate_with_progress( self, cb: impl FnMut(usize, usize), ) -> Result<CreateTorrentResult>

Generate the .torrent file with a progress callback (current_piece, total_pieces).

§Errors

Returns an error if no files have been added, the piece size is invalid, or file I/O fails during hashing.

Trait Implementations§

Source§

impl Default for CreateTorrent

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.