Skip to content

Commit a5d8e16

Browse files
author
share121
committed
fix: 修复 reader 中没有判断状态码的错误
1. 修复 reader 中没有判断状态码的错误 2. 修复 writer 中 RandFileWriterStd 错误类型不是 FileWriterError 的问题
1 parent bf0dc29 commit a5d8e16

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fast-pull"
3-
version = "2.2.1"
3+
version = "2.2.2"
44
edition = "2024"
55
license = "MIT"
66
authors = ["share121 <[email protected]>"]

src/file/writer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub struct RandFileWriterStd {
9393
buffer_size: usize,
9494
}
9595
impl RandFileWriterStd {
96-
pub async fn new(file: File, size: u64, buffer_size: usize) -> Result<Self, io::Error> {
96+
pub async fn new(file: File, size: u64, buffer_size: usize) -> Result<Self, FileWriterError> {
9797
file.set_len(size).await?;
9898
Ok(Self {
9999
buffer: BufWriter::with_capacity(buffer_size, file),
@@ -105,7 +105,7 @@ impl RandFileWriterStd {
105105
}
106106
}
107107
impl RandWriter for RandFileWriterStd {
108-
type Error = io::Error;
108+
type Error = FileWriterError;
109109
async fn write(&mut self, range: ProgressEntry, bytes: Bytes) -> Result<(), Self::Error> {
110110
let pos = self.cache.partition_point(|(i, _)| i < &range.start);
111111
self.cache_size += bytes.len();

src/reqwest/reader.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ impl Stream for ReqwestStream {
8383
return self.poll_next(cx);
8484
}
8585
ResponseState::Ready(resp) => {
86+
if let Err(e) = resp.error_for_status_ref() {
87+
self.resp = ResponseState::None;
88+
return Poll::Ready(Some(Err(e)));
89+
}
8690
let mut chunk = pin!(resp.chunk());
8791
match chunk.try_poll_unpin(cx) {
8892
Poll::Ready(Ok(Some(chunk))) => chunk_global = Ok(chunk),

0 commit comments

Comments
 (0)