6 releases

Uses old Rust 2015

0.2.4 Sep 15, 2017
0.2.3 Sep 5, 2017
0.1.0 Aug 24, 2017
Download history 382/week @ 2021-10-03 519/week @ 2021-10-10 658/week @ 2021-10-17 475/week @ 2021-10-24 486/week @ 2021-10-31 595/week @ 2021-11-07 527/week @ 2021-11-14 390/week @ 2021-11-21 702/week @ 2021-11-28 734/week @ 2021-12-05 673/week @ 2021-12-12 567/week @ 2021-12-19 203/week @ 2021-12-26 790/week @ 2022-01-02 815/week @ 2022-01-09 741/week @ 2022-01-16

2,562 downloads per month
Used in 19 crates (12 directly)

LGPL-3.0

2MB
12K SLoC

Rust-Chardet

Rust-Charset on Travis CI

Rust version of chardet.

Usage

Put this in your Cargo.toml:

[dependencies]
chardet = "0.2"

Then put this in your crate root:

extern crate chardet;

Using with encoding:

extern crate chardet;
extern crate encoding;
use chardet;
use std::fs::OpenOptions;
use std::io::prelude::*;
use encoding::DecoderTrap;
use encoding::label::encoding_from_whatwg_label;

// open text file
let mut fh = OpenOptions::new().read(true).open(filepath).expect(
    "Could not open file",
);
let mut reader: Vec<u8> = Vec::new();

// read file
fh.read_to_end(&mut reader).expect("Could not read file");

// detect charset of the file
let result = detect(&reader);
// result.0 Encode
// result.1 Confidence
// result.2 Language

// decode file into utf-8
let coder = encoding_from_whatwg_label(charset2encoding(&result.0));
if coder.is_some() {
    let utf8reader = coder.unwrap().decode(&reader, DecoderTrap::Ignore).expect("Error");
}

No runtime deps

Y