struct Download {
job: Job,
headers: Arc<[(HeaderName, HeaderValue)]>,
agent: Agent,
connect: Sender<Event>,
next_connection: usize,
parts: Vec<Part>,
partial: Option<Partial>,
total: Option<u64>,
speed: u64,
paused: bool,
meter: SpeedMeter,
last_report: Option<Instant>,
}Expand description
A download in progress, as its own thread sees it.
Fields§
§job: Job§headers: Arc<[(HeaderName, HeaderValue)]>§agent: Agent§connect: Sender<Event>§next_connection: usizeThe id the next connection gets.
parts: Vec<Part>In the order they come in the file, which they cover between them.
partial: Option<Partial>The file being written, once a server has answered.
total: Option<u64>The whole file’s length, when the server said.
speed: u64§paused: bool§meter: SpeedMeter§last_report: Option<Instant>Implementations§
Source§impl Download
impl Download
Sourcefn follow(
&mut self,
events: &Receiver<Event>,
report: &impl Fn(Report) -> Result<(), Abandoned>,
) -> Result<Report, Stopped>
fn follow( &mut self, events: &Receiver<Event>, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<Report, Stopped>
Handles events until the file is saved, giving the report that says so, or the download stops.
Sourcefn next_event(
&mut self,
events: &Receiver<Event>,
report: &impl Fn(Report) -> Result<(), Abandoned>,
) -> Result<Event, Stopped>
fn next_event( &mut self, events: &Receiver<Event>, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<Event, Stopped>
Waits for the next event, trying again each part whose wait to retry ends first.
Sourcefn retry_due(
&mut self,
report: &impl Fn(Report) -> Result<(), Abandoned>,
) -> Result<(), Abandoned>
fn retry_due( &mut self, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<(), Abandoned>
Starts a connection again for each part whose wait to retry is over, saying the download is under way again if nothing was.
Sourcefn is_waiting(&self) -> bool
fn is_waiting(&self) -> bool
Whether no connection is running, only parts waiting to retry.
Sourcefn part_of(&self, id: usize) -> Option<usize>
fn part_of(&self, id: usize) -> Option<usize>
Which part connection id is fetching, unless it has been stopped.
Sourcefn dial(&mut self, index: usize)
fn dial(&mut self, index: usize)
Starts a connection for what isn’t saved yet of the part at index. The whole
file is asked for as a range while the download may still split it, so the answer
says whether the server can send parts.
fn progress(&self) -> Progress
Sourcefn pause(
&mut self,
report: &impl Fn(Report) -> Result<(), Abandoned>,
) -> Result<(), Abandoned>
fn pause( &mut self, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<(), Abandoned>
Stops every connection, keeping what they saved, unless already paused.
Sourcefn resume(
&mut self,
report: &impl Fn(Report) -> Result<(), Abandoned>,
) -> Result<Option<Report>, Stopped>
fn resume( &mut self, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<Option<Report>, Stopped>
Carries on after a pause with a new connection for each part not yet saved, unless the file was complete, when it is saved at once.
fn is_complete(&self) -> bool
Sourcefn answered(&mut self, index: usize, answer: &Answer) -> Result<(), Stopped>
fn answered(&mut self, index: usize, answer: &Answer) -> Result<(), Stopped>
Opens the file for the connection the server answered, from where its body begins: a new partial file the first time, when the file may also be split into parts.
Sourcefn create(&mut self, answer: &Answer) -> Result<File, Stopped>
fn create(&mut self, answer: &Answer) -> Result<File, Stopped>
Creates the partial file for the first answer, and splits the file into parts when the download may and the server can send them, starting a connection for each part after the first.
fn partial_path(&self) -> &Path
fn wrote( &mut self, index: usize, bytes: u64, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<(), Abandoned>
Sourcefn ended(
&mut self,
index: usize,
ended: Result<(), ConnectionError>,
report: &impl Fn(Report) -> Result<(), Abandoned>,
) -> Result<Option<Report>, Stopped>
fn ended( &mut self, index: usize, ended: Result<(), ConnectionError>, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<Option<Report>, Stopped>
Handles the end of the part at index’s connection: makes sure what it wrote is
on disk, and saves the file once every part is, giving the report that says so. A
failure that may pass is tried again later while retries are left.
Sourcefn retry_later(
&mut self,
index: usize,
error: ConnectionError,
report: &impl Fn(Report) -> Result<(), Abandoned>,
) -> Result<(), Stopped>
fn retry_later( &mut self, index: usize, error: ConnectionError, report: &impl Fn(Report) -> Result<(), Abandoned>, ) -> Result<(), Stopped>
Stops the part at index’s failed connection, keeping what it saved, and tries it
again after a wait, saying so when nothing else is downloading.
§Errors
The failure, when it can’t pass or no retries are left.