6 releases

Uses old Rust 2015

0.2.4 Sep 15, 2017
0.2.3 Sep 5, 2017
0.1.0 Aug 24, 2017

#957 in Text processing

Download history 5467/week @ 2024-07-21 4440/week @ 2024-07-28 4720/week @ 2024-08-04 7949/week @ 2024-08-11 9105/week @ 2024-08-18 13825/week @ 2024-08-25 7512/week @ 2024-09-01 9800/week @ 2024-09-08 7588/week @ 2024-09-15 9126/week @ 2024-09-22 17525/week @ 2024-09-29 4544/week @ 2024-10-06 15282/week @ 2024-10-13 8479/week @ 2024-10-20 12923/week @ 2024-10-27 3241/week @ 2024-11-03

40,013 downloads per month
Used in 25 crates (17 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