#stream #io-stream #buffer #io

bytes-stream

Utility functions to work with stream of bytes

3 releases

0.0.3 May 14, 2023
0.0.2 Apr 1, 2023
0.0.1 Apr 1, 2023

#1999 in Asynchronous

Download history 33/week @ 2024-07-20 99/week @ 2024-07-27 11/week @ 2024-08-03 10/week @ 2024-08-10 21/week @ 2024-08-17 39/week @ 2024-08-24 15/week @ 2024-08-31 75/week @ 2024-09-07 26/week @ 2024-09-14 26/week @ 2024-09-21 15/week @ 2024-09-28 34/week @ 2024-10-05 20/week @ 2024-10-12 25/week @ 2024-10-19 12/week @ 2024-10-26 84/week @ 2024-11-02

143 downloads per month

MIT license

21KB
385 lines

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);
    });
}

Dependencies

~250KB