#charset #unicode #bufread #encoding

encodingbufreader

A BuferReader with encoding

1 unstable release

0.1.1 Jul 30, 2019
0.1.0 Jul 30, 2019

#6 in #bufread


Used in sunnycat

MIT license

10KB
143 lines

encoding bufreader

This is a bufreader with ecoding with wrap a BufReader inner.

install

cargo add encodingbufreader

usage

use encodingbufreader::{BufReaderEncoding};
use encoding::all::{UTF_8,GB18030};
let bytes = "This string\nwill be read".as_bytes();

let mut lines_iter = BufReaderEncoding::new(bytes,UTF_8).map(|l| l.unwrap());
assert_eq!(lines_iter.next(), Some(String::from("This string")));
assert_eq!(lines_iter.next(), Some(String::from("will be read")));
assert_eq!(lines_iter.next(), None);

let bytes: &[u8] = &[
            213, 226, 202, 199, 210, 187, 184, 246, 215, 214, 183, 251, 180, 174, 10, 189, 171,
            187, 225, 177, 187, 182, 193, 200, 161,
        ];
for line in BufReaderEncoding::new(bytes, GB18030)
            .lines()
            .map(|l| l.unwrap()){
    println!("{}",line);
            }

lib.rs:

encodingbufreader

encodingbufreader is a BufReader with encoding.

Dependencies

~2MB
~30K SLoC