fix(check): {Async}Get::check wasn't working correctly

This commit is contained in:
Kat Marchán 2019-10-17 22:44:46 -04:00
parent 398773547b
commit d08629cf55
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
2 changed files with 14 additions and 2 deletions

View File

@ -18,7 +18,7 @@ pub struct Reader {
impl std::io::Read for Reader {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let amt = self.fd.read(buf)?;
self.checker.input(&buf);
self.checker.input(&buf[..amt]);
Ok(amt)
}
}
@ -41,7 +41,7 @@ impl AsyncRead for AsyncReader {
buf: &mut [u8],
) -> Poll<std::io::Result<usize>> {
let amt = futures::ready!(Pin::new(&mut self.fd).poll_read(cx, buf))?;
self.checker.input(&buf);
self.checker.input(&buf[..amt]);
Poll::Ready(Ok(amt))
}
}

View File

@ -56,6 +56,8 @@ impl AsyncGet {
/// let mut handle = cacache::get::open("./my-cache", "my-key").await?;
/// let mut str = String::new();
/// handle.read_to_string(&mut str).await?;
/// // Remember to check that the data you got was correct!
/// handle.check()?;
/// # Ok(())
/// # }
/// ```
@ -89,6 +91,8 @@ where
/// let mut handle = cacache::get::open_hash("./my-cache", sri).await?;
/// let mut str = String::new();
/// handle.read_to_string(&mut str).await?;
/// // Remember to check that the data you got was correct!
/// handle.check()?;
/// # Ok(())
/// # }
/// ```
@ -197,6 +201,8 @@ impl Get {
/// let mut handle = cacache::get::open_sync("./my-cache", "my-key")?;
/// let mut str = String::new();
/// handle.read_to_string(&mut str)?;
/// // Remember to check that the data you got was correct!
/// handle.check()?;
/// # Ok(())
/// # }
/// ```
@ -222,6 +228,8 @@ where
/// let mut handle = cacache::get::open_hash_sync("./my-cache", sri)?;
/// let mut str = String::new();
/// handle.read_to_string(&mut str)?;
/// // Remember to check that the data you got was correct!
/// handle.check()?;
/// # Ok(())
/// # }
/// ```
@ -312,6 +320,7 @@ mod tests {
let mut handle = crate::get::open(&dir, "my-key").await.unwrap();
let mut str = String::new();
handle.read_to_string(&mut str).await.unwrap();
handle.check().unwrap();
assert_eq!(str, String::from("hello world"));
})
}
@ -328,6 +337,7 @@ mod tests {
let mut handle = crate::get::open_hash(&dir, sri).await.unwrap();
let mut str = String::new();
handle.read_to_string(&mut str).await.unwrap();
handle.check().unwrap();
assert_eq!(str, String::from("hello world"));
})
}
@ -342,6 +352,7 @@ mod tests {
let mut handle = crate::get::open_sync(&dir, "my-key").unwrap();
let mut str = String::new();
handle.read_to_string(&mut str).unwrap();
handle.check().unwrap();
assert_eq!(str, String::from("hello world"));
}
@ -355,6 +366,7 @@ mod tests {
let mut handle = crate::get::open_hash_sync(&dir, sri).unwrap();
let mut str = String::new();
handle.read_to_string(&mut str).unwrap();
handle.check().unwrap();
assert_eq!(str, String::from("hello world"));
}
}