Skip to content

Commit d5cf2a6

Browse files
committed
chore: merge
2 parents c2ba6ac + b942084 commit d5cf2a6

File tree

13 files changed

+75
-117
lines changed

13 files changed

+75
-117
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ jobs:
3434
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
3535
3636
- name: Test
37-
run: cargo test --all --verbose
37+
run: cargo test --workspace --all-features --all-targets --verbose
3838

3939
- name: Build
40-
run: cargo build --all --verbose
40+
run: cargo build --workspace --all-features --all-targets --verbose
4141

4242
- name: Clippy
43-
run: cargo clippy --all --verbose -- -Dwarnings
43+
run: cargo clippy --workspace --all-features --all-targets --verbose -- -Dwarnings
4444

4545
check-minimal:
4646
name: Check minimal versions
@@ -63,7 +63,7 @@ jobs:
6363
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
6464
6565
- name: Check minimal versions
66-
run: cargo check --all --all-targets -Z minimal-versions
66+
run: cargo check --workspace --all-features --all-targets -Z minimal-versions
6767

6868
format:
6969
runs-on: ubuntu-latest
@@ -78,4 +78,4 @@ jobs:
7878
components: rustfmt
7979

8080
- name: Run rustfmt
81-
run: cargo fmt --all -- --check
81+
run: cargo fmt --all --check

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ authors = ["share121 <[email protected]>", "Cyan Changes <[email protected]>"]
1313
spin = { version = "0.10.0", features = [
1414
"spin_mutex",
1515
], default-features = false }
16-
fast-pull = { version = "3.0.5", path = "crates/fast-pull" }
17-
fast-steal = { version = "6.0.5", path = "crates/fast-steal" }
16+
fast-pull = { version = "4.0.0", path = "crates/fast-pull" }
17+
fast-steal = { version = "6.0.6", path = "crates/fast-steal" }
1818
kanal = "0.1.1"
1919
bytes = { version = "1.10.1", default-features = false }
2020
futures = { version = "0.3.31", default-features = false }

crates/fast-down/src/reqwest/prefetch.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
use super::puller::ReqwestPuller;
1+
use std::future::Future;
2+
3+
use crate::UrlInfo;
24
use content_disposition;
3-
use fast_pull::UrlInfo;
45
use reqwest::{
56
Client, IntoUrl, StatusCode, Url,
67
header::{self, HeaderMap},
78
};
89
use sanitize_filename;
910

11+
pub trait Prefetch {
12+
fn prefetch(
13+
&self,
14+
url: impl IntoUrl + Send,
15+
) -> impl Future<Output = Result<UrlInfo, reqwest::Error>> + Send;
16+
}
17+
18+
impl Prefetch for Client {
19+
async fn prefetch(&self, url: impl IntoUrl + Send) -> Result<UrlInfo, reqwest::Error> {
20+
prefetch(self, url).await
21+
}
22+
}
23+
1024
fn get_file_size(headers: &HeaderMap, status: &StatusCode) -> u64 {
1125
if *status == StatusCode::PARTIAL_CONTENT {
1226
headers
@@ -36,12 +50,13 @@ fn get_filename(headers: &HeaderMap, final_url: &Url) -> String {
3650
.get(header::CONTENT_DISPOSITION)
3751
.and_then(|hv| hv.to_str().ok())
3852
.and_then(|s| content_disposition::parse_content_disposition(s).filename_full())
53+
.map(|s| urlencoding::decode(&s).map(String::from).unwrap_or(s))
3954
.filter(|s| !s.trim().is_empty());
4055

4156
let from_url = final_url
4257
.path_segments()
4358
.and_then(|mut segments| segments.next_back())
44-
.and_then(|s| urlencoding::decode(s).ok())
59+
.map(|s| urlencoding::decode(s).unwrap_or(s.into()))
4560
.filter(|s| !s.trim().is_empty())
4661
.map(|s| s.to_string());
4762

@@ -52,14 +67,14 @@ fn get_filename(headers: &HeaderMap, final_url: &Url) -> String {
5267
sanitize_filename::sanitize_with_options(
5368
&raw_name,
5469
sanitize_filename::Options {
55-
windows: true,
56-
truncate: true,
70+
windows: false,
71+
truncate: false,
5772
replacement: "_",
5873
},
5974
)
6075
}
6176

62-
async fn prefetch(client: &Client, url: impl IntoUrl + Send) -> Result<UrlInfo, reqwest::Error> {
77+
async fn prefetch(client: &Client, url: impl IntoUrl) -> Result<UrlInfo, reqwest::Error> {
6378
let url = url.into_url()?;
6479
let resp = match client.head(url.clone()).send().await {
6580
Ok(resp) => resp,
@@ -69,23 +84,19 @@ async fn prefetch(client: &Client, url: impl IntoUrl + Send) -> Result<UrlInfo,
6984
Ok(resp) => resp,
7085
Err(_) => return prefetch_fallback(url, client).await,
7186
};
72-
73-
let status = resp.status();
74-
let final_url = resp.url();
75-
76-
let resp_headers = resp.headers();
77-
let size = get_file_size(resp_headers, &status);
78-
7987
let supports_range = match resp.headers().get(header::ACCEPT_RANGES) {
8088
Some(accept_ranges) => accept_ranges
8189
.to_str()
8290
.ok()
8391
.map(|v| v.split(' '))
8492
.and_then(|supports| supports.into_iter().find(|&ty| ty == "bytes"))
8593
.is_some(),
86-
None => return prefetch_fallback(url, self).await,
94+
None => return prefetch_fallback(url, client).await,
8795
};
88-
96+
let status = resp.status();
97+
let resp_headers = resp.headers();
98+
let size = get_file_size(resp_headers, &status);
99+
let final_url = resp.url();
89100
Ok(UrlInfo {
90101
final_url: final_url.clone(),
91102
name: get_filename(resp_headers, final_url),
@@ -105,11 +116,10 @@ async fn prefetch_fallback(url: Url, client: &Client) -> Result<UrlInfo, reqwest
105116
.await?
106117
.error_for_status()?;
107118
let status = resp.status();
108-
let final_url = resp.url();
109-
110119
let resp_headers = resp.headers();
111120
let size = get_file_size(resp_headers, &status);
112121
let supports_range = status == StatusCode::PARTIAL_CONTENT;
122+
let final_url = resp.url();
113123
Ok(UrlInfo {
114124
final_url: final_url.clone(),
115125
name: get_filename(resp_headers, final_url),
@@ -123,8 +133,6 @@ async fn prefetch_fallback(url: Url, client: &Client) -> Result<UrlInfo, reqwest
123133

124134
#[cfg(test)]
125135
mod tests {
126-
use alloc::{format, vec};
127-
128136
use super::*;
129137

130138
#[tokio::test]

crates/fast-down/src/url_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use url::Url;
22

3+
#[derive(Debug)]
34
pub struct UrlInfo {
45
pub size: u64,
56
pub name: String,

crates/fast-pull/src/base/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ mod progress;
55
mod puller;
66
mod pusher;
77
mod total;
8-
#[cfg(feature = "reqwest")]
9-
pub(crate) mod url;
108

119
pub use data::SliceOrBytes;
1210
pub use event::*;

crates/fast-pull/src/base/url.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

crates/fast-pull/src/core/multi.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::base::SliceOrBytes;
44
use crate::{DownloadResult, Event, ProgressEntry, Puller, Pusher, ReadStream, WriteStream};
55
use alloc::boxed::Box;
66
use alloc::{sync::Arc, vec::Vec};
7-
use alloc::sync::Weak;
87
use core::ops::ControlFlow;
98
use core::{
109
num::{NonZero, NonZeroU64, NonZeroUsize},
@@ -84,22 +83,20 @@ where
8483
let join_handle = barrier.clone();
8584
let arbiter = Arbiter::new();
8685
let handle = arbiter.handle();
87-
let executor: ArbiterExecutor<R, W> = ArbiterExecutor {
86+
let executor: Arc<ArbiterExecutor<R, W>> = Arc::new(ArbiterExecutor {
8887
tx,
8988
puller,
9089
pusher,
91-
barrier,
9290
retry_gap: options.retry_gap,
9391
id: Arc::new(AtomicUsize::new(0)),
9492
min_chunk_size: options.min_chunk_size,
93+
barrier,
9594
arbiter,
96-
};
97-
let task_list = TaskList::run(
98-
options.concurrent,
99-
options.min_chunk_size,
100-
&options.download_chunks[..],
101-
executor,
102-
);
95+
});
96+
let task_list = Arc::new(TaskList::run(&options.download_chunks[..], executor));
97+
task_list
98+
.clone()
99+
.set_threads(options.concurrent, options.min_chunk_size);
103100
DownloadResult::new(
104101
event_chain,
105102
join_handle,

crates/fast-pull/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ mod base;
55
mod core;
66
#[cfg(feature = "file")]
77
pub mod file;
8-
#[cfg(feature = "reqwest")]
9-
pub mod reqwest;
108
pub use base::*;
119
pub use core::*;

crates/fast-pull/src/reqwest/mod.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)