Skip to main content

Crate stream_chunkrec

Crate stream_chunkrec 

Source
Expand description

§stream-chunkrec

Recombine streaming token deltas (bytes from a server-sent-event body, an HTTP chunk transfer, or any other framed source) into valid UTF-8 text.

Streams that arrive byte-by-byte can split a multi-byte UTF-8 sequence across two chunks. Naive String::from_utf8_lossy(chunk) turns the split fragments into replacement characters.

This crate buffers the trailing partial codepoint between pushes and emits only the bytes that resolve into whole characters.

§Example

use stream_chunkrec::Recombiner;
let mut r = Recombiner::new();
// "café" = 63 61 66 C3 A9
assert_eq!(r.push(&[0x63, 0x61, 0x66, 0xC3]), "caf"); // C3 is incomplete
assert_eq!(r.push(&[0xA9]), "é"); // completes the codepoint
assert_eq!(r.flush(), "");

Structs§

Recombiner
UTF-8-safe streaming recombiner.