From d08629cf5547f6aad8147f319fee5d30accf89a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Thu, 17 Oct 2019 22:44:46 -0400 Subject: [PATCH] fix(check): {Async}Get::check wasn't working correctly --- src/content/read.rs | 4 ++-- src/get.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/content/read.rs b/src/content/read.rs index fa106d0..1e5b820 100644 --- a/src/content/read.rs +++ b/src/content/read.rs @@ -18,7 +18,7 @@ pub struct Reader { impl std::io::Read for Reader { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { 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> { 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)) } } diff --git a/src/get.rs b/src/get.rs index 925c063..e79a82f 100644 --- a/src/get.rs +++ b/src/get.rs @@ -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")); } }