pub struct CreateTorrent { /* private fields */ }Expand description
Builder for creating .torrent files.
Implementations§
Source§impl CreateTorrent
impl CreateTorrent
Sourcepub fn add_directory(self, path: impl AsRef<Path>) -> Self
pub fn add_directory(self, path: impl AsRef<Path>) -> Self
Add all files from a directory recursively.
Sourcepub fn set_name(self, name: impl Into<String>) -> Self
pub fn set_name(self, name: impl Into<String>) -> Self
Set the torrent name (defaults to the file/directory name).
Sourcepub fn set_piece_size(self, bytes: u64) -> Self
pub fn set_piece_size(self, bytes: u64) -> Self
Set the piece size in bytes (must be a power of 2, ≥ 16384).
Sourcepub fn set_comment(self, s: impl Into<String>) -> Self
pub fn set_comment(self, s: impl Into<String>) -> Self
Set the comment field.
Sourcepub fn set_creator(self, s: impl Into<String>) -> Self
pub fn set_creator(self, s: impl Into<String>) -> Self
Set the creator field.
Sourcepub fn set_creation_date(self, ts: i64) -> Self
pub fn set_creation_date(self, ts: i64) -> Self
Set the creation date (unix timestamp). Defaults to current time.
Sourcepub fn set_private(self, private: bool) -> Self
pub fn set_private(self, private: bool) -> Self
Set the private flag (BEP 27).
Sourcepub fn set_source(self, s: impl Into<String>) -> Self
pub fn set_source(self, s: impl Into<String>) -> Self
Set the source tag (private tracker identification).
Sourcepub fn add_tracker(self, url: impl Into<String>, tier: usize) -> Self
pub fn add_tracker(self, url: impl Into<String>, tier: usize) -> Self
Add a tracker URL at the given tier.
Sourcepub fn add_web_seed(self, url: impl Into<String>) -> Self
pub fn add_web_seed(self, url: impl Into<String>) -> Self
Add a BEP 19 web seed URL (GetRight-style).
Sourcepub fn add_http_seed(self, url: impl Into<String>) -> Self
pub fn add_http_seed(self, url: impl Into<String>) -> Self
Add a BEP 17 HTTP seed URL (Hoffman-style).
Sourcepub fn add_dht_node(self, host: impl Into<String>, port: u16) -> Self
pub fn add_dht_node(self, host: impl Into<String>, port: u16) -> Self
Add a DHT bootstrap node (BEP 5).
Sourcepub fn set_pad_file_limit(self, limit: Option<u64>) -> Self
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 fileSome(n)— pad after files with length > n
Sourcepub fn include_mtime(self, enabled: bool) -> Self
pub fn include_mtime(self, enabled: bool) -> Self
Include file modification times in the torrent.
Sourcepub fn include_symlinks(self, enabled: bool) -> Self
pub fn include_symlinks(self, enabled: bool) -> Self
Follow and record symlinks.
Sourcepub fn set_hash(self, piece: u32, hash: Id20) -> Self
pub fn set_hash(self, piece: u32, hash: Id20) -> Self
Set a pre-computed SHA1 hash for a piece (skips disk read during generation).
Sourcepub fn set_version(self, version: TorrentVersion) -> Self
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)
Sourcepub fn set_ssl_cert(self, cert_pem: Vec<u8>) -> Self
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.
Sourcepub fn generate(self) -> Result<CreateTorrentResult>
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.
Sourcepub fn generate_with_progress(
self,
cb: impl FnMut(usize, usize),
) -> Result<CreateTorrentResult>
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.