Skip to content

Commit

Permalink
Show process status for directly downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDing committed Oct 11, 2020
1 parent 46ecd79 commit 70673d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/app/core/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ impl HttpHandler {

self.uri = uri;

let content_length = {
match cl {
ContentLengthValue::DirectLength(l) => l,
ContentLengthValue::RangeLength(l) => l,
_ => 0,
}
};

// 2. Compare recorded content length with the above one
debug!("HttpHandler: compare recorded content length");
let mut direct = true;
Expand Down Expand Up @@ -222,7 +230,7 @@ impl HttpHandler {

// 5. Create receiver
debug!("HttpHandler: create receiver");
let mut httpreceiver = HttpReceiver::new(&self.output, direct)?;
let mut httpreceiver = HttpReceiver::new(&self.output, direct, content_length)?;
httpreceiver.start(receiver).await?;

// 6. Task succeeds. Remove rangerecorder file
Expand Down
10 changes: 7 additions & 3 deletions src/app/receive/http_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ pub struct HttpReceiver {
}

impl HttpReceiver {
pub fn new<P: AsRef<Path>>(output: P, direct: bool) -> Result<HttpReceiver> {
pub fn new<P: AsRef<Path>>(
output: P,
direct: bool,
content_length: u64,
) -> Result<HttpReceiver> {
let mut outputfile = File::new(&output, true)?;
outputfile.open()?;

let (rangerecorder, total, completed) = if direct {
(None, 0, 0)
(None, content_length, 0)
} else {
let mut rangerecorder =
RangeRecorder::new(&*(output.as_ref().to_string_lossy() + RECORDER_FILE_SUFFIX))?;
Expand Down Expand Up @@ -71,7 +75,7 @@ impl HttpReceiver {
let completed = self.ratestatus.total();
let rate = self.ratestatus.rate();

let eta = if self.rangerecorder.is_some() {
let eta = if self.rangerecorder.is_some() || self.total != 0 {
let remains = total - completed;
// rate > 1.0 for overflow
if remains > 0 && rate > 1.0 {
Expand Down

0 comments on commit 70673d2

Please sign in to comment.