Crates.io | encodingbufreader |
lib.rs | encodingbufreader |
version | 0.1.1 |
source | src |
created_at | 2019-07-30 02:39:45.475258 |
updated_at | 2019-07-30 03:24:57.531892 |
description | A BuferReader with encoding. |
homepage | https://github.com/zhnxin/encodingbufreader |
repository | https://github.com/zhnxin/encodingbufreader |
max_upload_size | |
id | 152783 |
size | 9,786 |
This is a bufreader with ecoding with wrap a BufReader inner.
cargo add encodingbufreader
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);
}