This commit is contained in:
2022-06-19 04:32:35 +00:00
committed by GitHub
parent 3ade555e2c
commit 3a35c88c5f
3 changed files with 36 additions and 0 deletions

View File

@@ -27,6 +27,12 @@ impl PdFileStatus {
pub fn is_downloading(&self) -> bool {
*self == PdFileStatus::Downloading
}
#[inline]
/// Returns true if the download is started.
pub fn is_started(&self) -> bool {
*self == PdFileStatus::Started
}
}
/// The type of the downloader.

View File

@@ -224,6 +224,12 @@ impl PdFile {
self.status.get_ref().is_downloading()
}
#[inline]
/// Returns true if the download is started.
pub fn is_started(&self) -> bool {
self.status.get_ref().is_started()
}
#[inline]
/// Returns true if stored in memory only.
fn is_mem_only(&self) -> bool {

View File

@@ -142,6 +142,25 @@ pub async fn create_download_tasks_simple<
handle_download(d, result).await
}
/// Do first job when download in multiple mode.
pub async fn create_download_tasks_multi_first<
T: Seek + Write + Send + Sync + ClearFile + GetTargetFileName,
>(
d: Arc<DownloaderInternal<T>>,
) -> Result<(), DownloaderError> {
let result = d
.client
.get(d.url.deref().clone(), d.headers.as_ref().clone())
.await
.try_err(gettext("Failed to get url."))?;
let status = result.status();
if status.as_u16() >= 400 {
return Err(DownloaderError::from(status));
}
// # TODO
Ok(())
}
/// Handle download process
pub async fn handle_download<T: Seek + Write + Send + Sync + ClearFile + GetTargetFileName>(
d: Arc<DownloaderInternal<T>>,
@@ -224,6 +243,11 @@ pub async fn check_tasks<
if !d.is_multi_threads() {
let task = tokio::spawn(create_download_tasks_simple(Arc::clone(&d)));
d.add_task(task);
} else {
if d.pd.is_started() {
let task = tokio::spawn(create_download_tasks_multi_first(Arc::clone(&d)));
d.add_task(task);
}
}
loop {
check_dropped!(d);