Struct lava_torrent::torrent::v1::TorrentBuild
source · pub struct TorrentBuild { /* private fields */ }
Expand description
Handle for non-blocking torrent builds.
See TorrentBuilder::build_non_blocking()
for an example.
Implementations§
source§impl TorrentBuild
impl TorrentBuild
sourcepub fn get_progress(&self) -> u8
pub fn get_progress(&self) -> u8
Get the current progress of the torrent build.
The progress is represented in percentage and returned as an integer.
It’s calculated as number_of_pieces_processed / number_of_pieces_total * 100
.
Note that get_progress()
returning 100
merely means that all pieces have
been hashed and nothing more. If you call get_output()
immediately afterwards,
it might still block for a brief moment. To avoid blocking, only call get_output()
after is_finished()
returns true
.
In other words
// do this
use lava_torrent::torrent::v1::TorrentBuilder;
let build = TorrentBuilder::new("dir/", 1048576).build_non_blocking().unwrap();
while !build.is_finished() {
std::thread::sleep(std::time::Duration::from_millis(100));
}
let torrent = build.get_output().unwrap();
instead of
// don't do this
use lava_torrent::torrent::v1::TorrentBuilder;
let build = TorrentBuilder::new("dir/", 1048576).build_non_blocking().unwrap();
while build.get_progress() < 100 {
std::thread::sleep(std::time::Duration::from_millis(100));
}
let torrent = build.get_output().unwrap();
sourcepub fn get_n_piece_processed(&self) -> u64
pub fn get_n_piece_processed(&self) -> u64
Get the number of pieces that have been processed so far.
sourcepub fn get_n_piece_total(&self) -> u64
pub fn get_n_piece_total(&self) -> u64
Get the total number of pieces to be processed.
Note that 0 will be returned in at least 2 cases:
- the torrent contains only empty files/dirs
- the actual value has not been calculated yet
sourcepub fn cancel(&self)
pub fn cancel(&self)
Cancel the torrent build.
cancel()
does not consume the TorrentBuild
. If you want, you can call
drop()
yourself.
Calling get_output()
after cancel()
will most likely give you an
Err(LavaTorrentError::TorrentBuilderFailure)
, but it’s also possible
for you to get an Ok(torrent)
(if you cancel after all pieces have been hashed).
sourcepub fn get_output(self) -> Result<Torrent, LavaTorrentError>
pub fn get_output(self) -> Result<Torrent, LavaTorrentError>
Retrieve the output of the torrent build.
This function will block if the build has not finished yet. You can
use is_finished()
to check if the build has finished.
sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Check if the torrent build has finished.