encodingbufreader

Crates.ioencodingbufreader
lib.rsencodingbufreader
version0.1.1
sourcesrc
created_at2019-07-30 02:39:45.475258
updated_at2019-07-30 03:24:57.531892
descriptionA BuferReader with encoding.
homepagehttps://github.com/zhnxin/encodingbufreader
repositoryhttps://github.com/zhnxin/encodingbufreader
max_upload_size
id152783
size9,786
(zhnxin)

documentation

README

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);
            }
Commit count: 4

cargo fmt