6 releases

Uses old Rust 2015

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

#1394 in Encoding

Download history 32050/week @ 2024-11-16 7633/week @ 2024-11-23 20580/week @ 2024-11-30 23022/week @ 2024-12-07 15888/week @ 2024-12-14 1029/week @ 2024-12-21 2911/week @ 2024-12-28 20831/week @ 2025-01-04 19559/week @ 2025-01-11 9912/week @ 2025-01-18 12024/week @ 2025-01-25 13362/week @ 2025-02-01 15312/week @ 2025-02-08 11363/week @ 2025-02-15 22609/week @ 2025-02-22 16611/week @ 2025-03-01

69,683 downloads per month
Used in 23 crates (16 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