MCPcopy Create free account
hub / github.com/RustCrypto/utils / test_async_write

Function test_async_write

digest-io-async/tests/mod.rs:28–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26
27#[tokio::test]
28async fn test_async_write() {
29 let data = b"the quick brown fox jumps over the lazy dog".repeat(1000);
30
31 // Feed the stream chunk by chunk with an odd sized buffer.
32 let chunks = stream::iter(
33 data.chunks(37)
34 .map(|c| Ok::<_, std::io::Error>(Bytes::copy_from_slice(c)))
35 .collect::<Vec<_>>(),
36 );
37 let mut source = StreamReader::new(chunks);
38
39 let mut writer = HashWriter::<Sha256, _>::new(Vec::new());
40 tokio::io::copy(&mut source, &mut writer).await.unwrap();
41 writer.flush().await.unwrap();
42
43 let (hasher, sink) = writer.into_parts();
44 assert_eq!(sink, data);
45 assert_eq!(hasher.finalize(), Sha256::digest(&data));
46}

Callers

nothing calls this directly

Calls 4

mapMethod · 0.80
unwrapMethod · 0.45
flushMethod · 0.45
into_partsMethod · 0.45

Tested by

no test coverage detected