buf_read_splitter
buf_read_splitter as the ability to read a stream inside a buffer(fixed length or not), reading until defined pattern (like an array of [u8], or it more complex pattern)
Below an example with a separator as an array of bytes :
use Read;
use ;
// We simulate a stream with this content :
let input = "First<SEP>Second<SEP>Third<SEP>Fourth<SEP>Fifth".to_string;
let mut input_reader = input.as_bytes;
// We create a reader that will end at each "<SEP>" :
let mut reader = new;
// List of separate String will be listed in a Vector :
let mut words = Vecnew;
// Working variables :
let mut word = Stringnew;
let mut buf = vec!;
while
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
But it can also be a more complex pattern.
For example below a Matcher able to split a stream at each Mac, Unix or Windows end of line :
use ;
...so the reader can be created like this :
let mut reader = BufReadSplitter::new( &mut input_reader, AllEndOfLineMatcher::new(), Options::default() );
The separator pattern can be changed on the fly by calling the function matcher :
reader.matcher(SimpleMatcher::new(b"<CHANGE SEP>"))
The size of the buffer part can be limited.
For example to limit the stream to read only 100 bytes :
reader.set_limit_read(Some(100));
...and to reinitialize it :
reader.set_limit_read(None);\
A call to .next_part() pass to the next part, however the end was reached or not, so it skips what has not been readed.
For debug purpose, you can activate the "log" features in the Cargo.toml :
[dependencies]
buf_read_splitter = { path = "../buf_read_splitter_v0.3/buf_read_splitter", features = ["log",] }
For more information :\
- [https://docs.rs/buf_read_splitter/latest/buf_read_splitter/]\
- [https://crates.io/crates/buf_read_splitter]
A suggestion or bug alert ? Feel free to fill an issue :\
- [https://github.com/flogbl/buf_read_splitter/issues]
You can also contact me :
- [https://github.com/flogbl]
Thanks for your interest!
License: MIT