bytes-stream

Crates.iobytes-stream
lib.rsbytes-stream
version0.0.3
sourcesrc
created_at2023-04-01 19:35:30.297806
updated_at2023-05-14 12:55:44.348455
descriptionUtility functions to work with stream of bytes
homepage
repositoryhttps://github.com/reu/bytes-stream
max_upload_size
id827478
size21,758
Rodrigo Navarro (reu)

documentation

README

bytes-stream

Utility functions to work with Streams of Bytes.

Examples

Split a stream of bytes into chunks:

use bytes::Bytes;
use bytes_stream::BytesStream;
use futures::StreamExt;

fn main() {
    futures::executor::block_on(async {
        let stream = futures::stream::iter(vec![
            Bytes::from_static(&[1, 2, 3]),
            Bytes::from_static(&[4, 5, 6]),
            Bytes::from_static(&[7, 8, 9]),
        ]);

        let mut stream = stream.bytes_chunks(4);

        assert_eq!(stream.next().await, Some(Bytes::from_static(&[1, 2, 3, 4])));
        assert_eq!(stream.next().await, Some(Bytes::from_static(&[5, 6, 7, 8])));
        assert_eq!(stream.next().await, Some(Bytes::from_static(&[9])));
        assert_eq!(stream.next().await, None);
    });
}
Commit count: 6

cargo fmt