| 8 | |
| 9 | #[tokio::test] |
| 10 | async fn test_async_read() { |
| 11 | let data = b"the quick brown fox jumps over the lazy dog".repeat(1000); |
| 12 | |
| 13 | // Feed the stream chunk by chunk with an odd sized buffer. |
| 14 | let chunks = stream::iter( |
| 15 | data.chunks(37) |
| 16 | .map(|c| Ok::<_, std::io::Error>(Bytes::copy_from_slice(c))) |
| 17 | .collect::<Vec<_>>(), |
| 18 | ); |
| 19 | let mut reader = HashReader::<Sha256, _>::new(StreamReader::new(chunks)); |
| 20 | let mut sink = Vec::new(); |
| 21 | tokio::io::copy(&mut reader, &mut sink).await.unwrap(); |
| 22 | |
| 23 | assert_eq!(sink, data); |
| 24 | assert_eq!(reader.finalize(), Sha256::digest(&data)); |
| 25 | } |
| 26 | |
| 27 | #[tokio::test] |
| 28 | async fn test_async_write() { |