Skip to content

Commit ef458ab

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

File tree

17 files changed

+110
-143
lines changed

17 files changed

+110
-143
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/curl/puller.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ impl ReadStream for WorkerPuller {
5050
async fn read_with<'a, F, Fut, Ret>(&'a mut self, read_fn: F) -> Result<Ret, Self::Error>
5151
where
5252
F: FnOnce(SliceOrBytes<'a>) -> Fut,
53-
Fut: Future<Output=Ret>
53+
Fut: Future<Output = Ret>,
5454
{
55-
let data = self.rx_data.recv().await.map_err(|_| io::Error::new(io::ErrorKind::BrokenPipe, "data channel closed"))?;
55+
let data = self
56+
.rx_data
57+
.recv()
58+
.await
59+
.map_err(|_| io::Error::new(io::ErrorKind::BrokenPipe, "data channel closed"))?;
5660
Ok(read_fn(data.into()).await)
5761
}
5862
}
@@ -64,8 +68,7 @@ impl Puller for WorkerFetcher {
6468
async fn init_read(
6569
&self,
6670
maybe_entry: Option<&ProgressEntry>,
67-
) -> Result<impl ReadStream<Error = Self::StreamError> + Send + Unpin, CreateTaskError>
68-
{
71+
) -> Result<impl ReadStream<Error = Self::StreamError> + Send + Unpin, CreateTaskError> {
6972
let (tx_data, rx_data) = kanal::bounded(self.options.data_channel_cap);
7073
let signal: Arc<DataSignal> = Default::default();
7174
let (tx_ret, ret) = oneshot::channel();

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/mock.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
extern crate alloc;
2-
use crate::{
3-
ProgressEntry, Puller, Pusher, ReadStream, SliceOrBytes, WriteStream,
4-
};
2+
use crate::{ProgressEntry, Puller, Pusher, ReadStream, SliceOrBytes, WriteStream};
53
use alloc::vec;
64
use alloc::{sync::Arc, vec::Vec};
75
use core::sync::atomic::{AtomicUsize, Ordering};
@@ -31,7 +29,7 @@ impl ReadStream for MockPullStream {
3129
let start = self.1.fetch_add(1, Ordering::SeqCst);
3230
let end = core::cmp::min(start + 1, self.2);
3331
if start >= end {
34-
return Ok(read_fn(SliceOrBytes::empty()).await)
32+
return Ok(read_fn(SliceOrBytes::empty()).await);
3533
}
3634
Ok(read_fn(self.0[start..end].into()).await)
3735
}
@@ -46,7 +44,9 @@ impl Puller for MockRandPuller {
4644
Ok(MockPullStream(
4745
self.0.clone(),
4846
AtomicUsize::new(maybe_entry.map(|entry| entry.start as usize).unwrap_or(0)),
49-
maybe_entry.map(|entry| entry.end as usize).unwrap_or(self.0.len()),
47+
maybe_entry
48+
.map(|entry| entry.end as usize)
49+
.unwrap_or(self.0.len()),
5050
))
5151
}
5252
}
@@ -67,9 +67,9 @@ impl ReadStream for MockSeqPuller {
6767
{
6868
let idx = self.1.fetch_add(1, Ordering::SeqCst);
6969
if idx >= self.0.len() {
70-
return Ok(read_fn(SliceOrBytes::empty()).await)
70+
return Ok(read_fn(SliceOrBytes::empty()).await);
7171
}
72-
Ok(read_fn(self.0[idx..(idx+1)].into()).await)
72+
Ok(read_fn(self.0[idx..(idx + 1)].into()).await)
7373
}
7474
}
7575

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate alloc;
22

3-
use alloc::boxed::Box;
43
use crate::Event;
4+
use alloc::boxed::Box;
55
use alloc::sync::Arc;
66
use core::sync::atomic::{AtomicBool, Ordering};
77
use kanal::AsyncReceiver;

0 commit comments

Comments
 (0)