chardet-rs 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. chardet_rs-0.1.0/Cargo.lock +393 -0
  2. chardet_rs-0.1.0/Cargo.toml +19 -0
  3. chardet_rs-0.1.0/PKG-INFO +258 -0
  4. chardet_rs-0.1.0/README.md +243 -0
  5. chardet_rs-0.1.0/chardet/Cargo.toml +32 -0
  6. chardet_rs-0.1.0/chardet/README.md +243 -0
  7. chardet_rs-0.1.0/chardet/models/confusion.bin +0 -0
  8. chardet_rs-0.1.0/chardet/models/idf.bin +32 -0
  9. chardet_rs-0.1.0/chardet/models/models.bin +0 -0
  10. chardet_rs-0.1.0/chardet/models/rowmax.bin +0 -0
  11. chardet_rs-0.1.0/chardet/src/codecs/categories_data.rs +791 -0
  12. chardet_rs-0.1.0/chardet/src/codecs/dbcs.bin +0 -0
  13. chardet_rs-0.1.0/chardet/src/codecs/mod.rs +773 -0
  14. chardet_rs-0.1.0/chardet/src/codecs/sbcs_data.rs +167 -0
  15. chardet_rs-0.1.0/chardet/src/enums.rs +33 -0
  16. chardet_rs-0.1.0/chardet/src/lib.rs +144 -0
  17. chardet_rs-0.1.0/chardet/src/main.rs +219 -0
  18. chardet_rs-0.1.0/chardet/src/models/format.rs +113 -0
  19. chardet_rs-0.1.0/chardet/src/models/mod.rs +336 -0
  20. chardet_rs-0.1.0/chardet/src/output_names.rs +104 -0
  21. chardet_rs-0.1.0/chardet/src/pipeline/ascii.rs +29 -0
  22. chardet_rs-0.1.0/chardet/src/pipeline/binary.rs +50 -0
  23. chardet_rs-0.1.0/chardet/src/pipeline/bom.rs +39 -0
  24. chardet_rs-0.1.0/chardet/src/pipeline/confusion.rs +568 -0
  25. chardet_rs-0.1.0/chardet/src/pipeline/escape.rs +296 -0
  26. chardet_rs-0.1.0/chardet/src/pipeline/language.rs +97 -0
  27. chardet_rs-0.1.0/chardet/src/pipeline/magic.rs +257 -0
  28. chardet_rs-0.1.0/chardet/src/pipeline/markup.rs +240 -0
  29. chardet_rs-0.1.0/chardet/src/pipeline/mod.rs +20 -0
  30. chardet_rs-0.1.0/chardet/src/pipeline/orchestrator.rs +380 -0
  31. chardet_rs-0.1.0/chardet/src/pipeline/postprocess.rs +471 -0
  32. chardet_rs-0.1.0/chardet/src/pipeline/statistical.rs +33 -0
  33. chardet_rs-0.1.0/chardet/src/pipeline/structural.rs +432 -0
  34. chardet_rs-0.1.0/chardet/src/pipeline/utf1632.rs +241 -0
  35. chardet_rs-0.1.0/chardet/src/pipeline/utf8.rs +123 -0
  36. chardet_rs-0.1.0/chardet/src/pipeline/validity.rs +19 -0
  37. chardet_rs-0.1.0/chardet/src/registry.rs +137 -0
  38. chardet_rs-0.1.0/chardet/src/registry_data.rs +833 -0
  39. chardet_rs-0.1.0/chardet/src/result.rs +65 -0
  40. chardet_rs-0.1.0/chardet/src/utils.rs +90 -0
  41. chardet_rs-0.1.0/chardet/tests/detect.rs +200 -0
  42. chardet_rs-0.1.0/chardet-py/Cargo.toml +17 -0
  43. chardet_rs-0.1.0/chardet-py/dist/chardet_rs-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl +0 -0
  44. chardet_rs-0.1.0/chardet-py/src/lib.rs +486 -0
  45. chardet_rs-0.1.0/pyproject.toml +30 -0
  46. chardet_rs-0.1.0/python/chardet/__init__.py +37 -0
  47. chardet_rs-0.1.0/python/chardet/cli.py +97 -0
  48. chardet_rs-0.1.0/python/chardet/enums.py +30 -0
  49. chardet_rs-0.1.0/python/chardet/equivalences.py +31 -0
  50. chardet_rs-0.1.0/python/chardet/output_names.py +109 -0
  51. chardet_rs-0.1.0/python/chardet/pipeline.py +40 -0
@@ -0,0 +1,393 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "adler2"
7
+ version = "2.0.1"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
10
+
11
+ [[package]]
12
+ name = "aho-corasick"
13
+ version = "1.1.5"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
16
+ dependencies = [
17
+ "memchr",
18
+ ]
19
+
20
+ [[package]]
21
+ name = "autocfg"
22
+ version = "1.5.1"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
25
+
26
+ [[package]]
27
+ name = "block-buffer"
28
+ version = "0.10.4"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
31
+ dependencies = [
32
+ "generic-array",
33
+ ]
34
+
35
+ [[package]]
36
+ name = "cfg-if"
37
+ version = "1.0.5"
38
+ source = "registry+https://github.com/rust-lang/crates.io-index"
39
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
40
+
41
+ [[package]]
42
+ name = "chardet-py"
43
+ version = "0.1.0"
44
+ dependencies = [
45
+ "chardet-rs",
46
+ "pyo3",
47
+ ]
48
+
49
+ [[package]]
50
+ name = "chardet-rs"
51
+ version = "0.1.0"
52
+ dependencies = [
53
+ "encoding_rs",
54
+ "flate2",
55
+ "once_cell",
56
+ "regex",
57
+ "sha2",
58
+ ]
59
+
60
+ [[package]]
61
+ name = "core_detect"
62
+ version = "1.0.0"
63
+ source = "registry+https://github.com/rust-lang/crates.io-index"
64
+ checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"
65
+
66
+ [[package]]
67
+ name = "cpufeatures"
68
+ version = "0.2.17"
69
+ source = "registry+https://github.com/rust-lang/crates.io-index"
70
+ checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
71
+ dependencies = [
72
+ "libc",
73
+ ]
74
+
75
+ [[package]]
76
+ name = "crc32fast"
77
+ version = "1.5.2"
78
+ source = "registry+https://github.com/rust-lang/crates.io-index"
79
+ checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78"
80
+ dependencies = [
81
+ "cfg-if",
82
+ ]
83
+
84
+ [[package]]
85
+ name = "crypto-common"
86
+ version = "0.1.7"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
89
+ dependencies = [
90
+ "generic-array",
91
+ "typenum",
92
+ ]
93
+
94
+ [[package]]
95
+ name = "digest"
96
+ version = "0.10.7"
97
+ source = "registry+https://github.com/rust-lang/crates.io-index"
98
+ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
99
+ dependencies = [
100
+ "block-buffer",
101
+ "crypto-common",
102
+ ]
103
+
104
+ [[package]]
105
+ name = "encoding_rs"
106
+ version = "0.8.42"
107
+ source = "registry+https://github.com/rust-lang/crates.io-index"
108
+ checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679"
109
+ dependencies = [
110
+ "cfg-if",
111
+ "core_detect",
112
+ "multiversion_no_op",
113
+ "rustversion",
114
+ "scopeguard",
115
+ "simdutf8",
116
+ ]
117
+
118
+ [[package]]
119
+ name = "flate2"
120
+ version = "1.1.10"
121
+ source = "registry+https://github.com/rust-lang/crates.io-index"
122
+ checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
123
+ dependencies = [
124
+ "crc32fast",
125
+ "miniz_oxide",
126
+ "zlib-rs",
127
+ ]
128
+
129
+ [[package]]
130
+ name = "generic-array"
131
+ version = "0.14.7"
132
+ source = "registry+https://github.com/rust-lang/crates.io-index"
133
+ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
134
+ dependencies = [
135
+ "typenum",
136
+ "version_check",
137
+ ]
138
+
139
+ [[package]]
140
+ name = "heck"
141
+ version = "0.5.0"
142
+ source = "registry+https://github.com/rust-lang/crates.io-index"
143
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
144
+
145
+ [[package]]
146
+ name = "indoc"
147
+ version = "2.0.7"
148
+ source = "registry+https://github.com/rust-lang/crates.io-index"
149
+ checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
150
+ dependencies = [
151
+ "rustversion",
152
+ ]
153
+
154
+ [[package]]
155
+ name = "libc"
156
+ version = "0.2.190"
157
+ source = "registry+https://github.com/rust-lang/crates.io-index"
158
+ checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78"
159
+
160
+ [[package]]
161
+ name = "memchr"
162
+ version = "2.8.3"
163
+ source = "registry+https://github.com/rust-lang/crates.io-index"
164
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
165
+
166
+ [[package]]
167
+ name = "memoffset"
168
+ version = "0.9.1"
169
+ source = "registry+https://github.com/rust-lang/crates.io-index"
170
+ checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
171
+ dependencies = [
172
+ "autocfg",
173
+ ]
174
+
175
+ [[package]]
176
+ name = "miniz_oxide"
177
+ version = "0.9.1"
178
+ source = "registry+https://github.com/rust-lang/crates.io-index"
179
+ checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
180
+ dependencies = [
181
+ "adler2",
182
+ "simd-adler32",
183
+ ]
184
+
185
+ [[package]]
186
+ name = "multiversion_no_op"
187
+ version = "1.0.0"
188
+ source = "registry+https://github.com/rust-lang/crates.io-index"
189
+ checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d"
190
+
191
+ [[package]]
192
+ name = "once_cell"
193
+ version = "1.21.4"
194
+ source = "registry+https://github.com/rust-lang/crates.io-index"
195
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
196
+
197
+ [[package]]
198
+ name = "portable-atomic"
199
+ version = "1.15.0"
200
+ source = "registry+https://github.com/rust-lang/crates.io-index"
201
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
202
+
203
+ [[package]]
204
+ name = "proc-macro2"
205
+ version = "1.0.107"
206
+ source = "registry+https://github.com/rust-lang/crates.io-index"
207
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
208
+ dependencies = [
209
+ "unicode-ident",
210
+ ]
211
+
212
+ [[package]]
213
+ name = "pyo3"
214
+ version = "0.23.5"
215
+ source = "registry+https://github.com/rust-lang/crates.io-index"
216
+ checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872"
217
+ dependencies = [
218
+ "cfg-if",
219
+ "indoc",
220
+ "libc",
221
+ "memoffset",
222
+ "once_cell",
223
+ "portable-atomic",
224
+ "pyo3-build-config",
225
+ "pyo3-ffi",
226
+ "pyo3-macros",
227
+ "unindent",
228
+ ]
229
+
230
+ [[package]]
231
+ name = "pyo3-build-config"
232
+ version = "0.23.5"
233
+ source = "registry+https://github.com/rust-lang/crates.io-index"
234
+ checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb"
235
+ dependencies = [
236
+ "once_cell",
237
+ "target-lexicon",
238
+ ]
239
+
240
+ [[package]]
241
+ name = "pyo3-ffi"
242
+ version = "0.23.5"
243
+ source = "registry+https://github.com/rust-lang/crates.io-index"
244
+ checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d"
245
+ dependencies = [
246
+ "libc",
247
+ "pyo3-build-config",
248
+ ]
249
+
250
+ [[package]]
251
+ name = "pyo3-macros"
252
+ version = "0.23.5"
253
+ source = "registry+https://github.com/rust-lang/crates.io-index"
254
+ checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da"
255
+ dependencies = [
256
+ "proc-macro2",
257
+ "pyo3-macros-backend",
258
+ "quote",
259
+ "syn",
260
+ ]
261
+
262
+ [[package]]
263
+ name = "pyo3-macros-backend"
264
+ version = "0.23.5"
265
+ source = "registry+https://github.com/rust-lang/crates.io-index"
266
+ checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028"
267
+ dependencies = [
268
+ "heck",
269
+ "proc-macro2",
270
+ "pyo3-build-config",
271
+ "quote",
272
+ "syn",
273
+ ]
274
+
275
+ [[package]]
276
+ name = "quote"
277
+ version = "1.0.47"
278
+ source = "registry+https://github.com/rust-lang/crates.io-index"
279
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
280
+ dependencies = [
281
+ "proc-macro2",
282
+ ]
283
+
284
+ [[package]]
285
+ name = "regex"
286
+ version = "1.13.1"
287
+ source = "registry+https://github.com/rust-lang/crates.io-index"
288
+ checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
289
+ dependencies = [
290
+ "aho-corasick",
291
+ "memchr",
292
+ "regex-automata",
293
+ "regex-syntax",
294
+ ]
295
+
296
+ [[package]]
297
+ name = "regex-automata"
298
+ version = "0.4.18"
299
+ source = "registry+https://github.com/rust-lang/crates.io-index"
300
+ checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
301
+ dependencies = [
302
+ "aho-corasick",
303
+ "memchr",
304
+ "regex-syntax",
305
+ ]
306
+
307
+ [[package]]
308
+ name = "regex-syntax"
309
+ version = "0.8.11"
310
+ source = "registry+https://github.com/rust-lang/crates.io-index"
311
+ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
312
+
313
+ [[package]]
314
+ name = "rustversion"
315
+ version = "1.0.23"
316
+ source = "registry+https://github.com/rust-lang/crates.io-index"
317
+ checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
318
+
319
+ [[package]]
320
+ name = "scopeguard"
321
+ version = "1.2.0"
322
+ source = "registry+https://github.com/rust-lang/crates.io-index"
323
+ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
324
+
325
+ [[package]]
326
+ name = "sha2"
327
+ version = "0.10.9"
328
+ source = "registry+https://github.com/rust-lang/crates.io-index"
329
+ checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
330
+ dependencies = [
331
+ "cfg-if",
332
+ "cpufeatures",
333
+ "digest",
334
+ ]
335
+
336
+ [[package]]
337
+ name = "simd-adler32"
338
+ version = "0.3.10"
339
+ source = "registry+https://github.com/rust-lang/crates.io-index"
340
+ checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
341
+
342
+ [[package]]
343
+ name = "simdutf8"
344
+ version = "0.1.5"
345
+ source = "registry+https://github.com/rust-lang/crates.io-index"
346
+ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
347
+
348
+ [[package]]
349
+ name = "syn"
350
+ version = "2.0.119"
351
+ source = "registry+https://github.com/rust-lang/crates.io-index"
352
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
353
+ dependencies = [
354
+ "proc-macro2",
355
+ "quote",
356
+ "unicode-ident",
357
+ ]
358
+
359
+ [[package]]
360
+ name = "target-lexicon"
361
+ version = "0.12.16"
362
+ source = "registry+https://github.com/rust-lang/crates.io-index"
363
+ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
364
+
365
+ [[package]]
366
+ name = "typenum"
367
+ version = "1.20.1"
368
+ source = "registry+https://github.com/rust-lang/crates.io-index"
369
+ checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
370
+
371
+ [[package]]
372
+ name = "unicode-ident"
373
+ version = "1.0.26"
374
+ source = "registry+https://github.com/rust-lang/crates.io-index"
375
+ checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
376
+
377
+ [[package]]
378
+ name = "unindent"
379
+ version = "0.2.4"
380
+ source = "registry+https://github.com/rust-lang/crates.io-index"
381
+ checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
382
+
383
+ [[package]]
384
+ name = "version_check"
385
+ version = "0.9.5"
386
+ source = "registry+https://github.com/rust-lang/crates.io-index"
387
+ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
388
+
389
+ [[package]]
390
+ name = "zlib-rs"
391
+ version = "0.6.8"
392
+ source = "registry+https://github.com/rust-lang/crates.io-index"
393
+ checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
@@ -0,0 +1,19 @@
1
+ [workspace]
2
+ resolver = "2"
3
+ members = ["chardet", "chardet-py"]
4
+
5
+ [workspace.package]
6
+ version = "0.1.0"
7
+ edition = "2021"
8
+ license = "0BSD"
9
+ repository = "https://github.com/thanatosmoe/chardet-rs"
10
+ homepage = "https://github.com/thanatosmoe/chardet-rs"
11
+ documentation = "https://docs.rs/chardet-rs"
12
+ authors = ["Thanatos"]
13
+ keywords = ["encoding", "charset", "detection", "unicode", "chardet"]
14
+ categories = ["text-processing", "encoding", "internationalization"]
15
+ rust-version = "1.74"
16
+
17
+ [profile.release]
18
+ lto = true
19
+ codegen-units = 1
@@ -0,0 +1,258 @@
1
+ Metadata-Version: 2.4
2
+ Name: chardet-rs
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Python :: 3
5
+ Classifier: Programming Language :: Rust
6
+ Classifier: Topic :: Text Processing :: Linguistic
7
+ Summary: Universal character encoding detector — Rust port of chardet 7
8
+ Author: Thanatos
9
+ License-Expression: 0BSD
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
12
+ Project-URL: Homepage, https://github.com/thanatosmoe/chardet-rs
13
+ Project-URL: Repository, https://github.com/thanatosmoe/chardet-rs
14
+
15
+ # chardet-rs
16
+
17
+ [![CI](https://github.com/thanatosmoe/chardet-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/thanatosmoe/chardet-rs/actions/workflows/ci.yml)
18
+ [![License: 0BSD](https://img.shields.io/badge/License-0BSD-blue.svg)](LICENSE)
19
+
20
+ A Rust rewrite of [chardet 7](https://github.com/chardet/chardet), the
21
+ universal character encoding detector. Same detection results, native Rust
22
+ core, optional Python bindings.
23
+
24
+ This is a faithful port: it reuses chardet 7's trained bigram model artifacts
25
+ and reproduces its 13-stage detection pipeline, aiming for byte-for-byte
26
+ identical output. On the full official corpus
27
+ ([chardet/test-data](https://github.com/chardet/test-data), 3,196 files) it
28
+ matches Python chardet 7 on **3,196/3,196** files — encoding, confidence
29
+ (full `f64` precision), language, and MIME type.
30
+
31
+ ## Why
32
+
33
+ - **Exact parity** — identical `encoding`, `confidence`, `language`, and
34
+ `mime_type` to chardet 7 on every corpus file.
35
+ - **Reuses the reference models** — the trained `models.bin`, `idf.bin`,
36
+ `rowmax.bin`, and `confusion.bin` artifacts are parsed directly, so accuracy
37
+ is chardet 7's accuracy.
38
+ - **Native Rust core** — a library crate plus a `chardetect` binary.
39
+ - **Drop-in Python bindings** — a PyO3 extension packaged as the `chardet`
40
+ module, including the `chardet.enums`, `chardet.pipeline`, and
41
+ `chardet.equivalences` submodules.
42
+
43
+ | | chardet-rs | Python chardet 7 |
44
+ | --- | --- | --- |
45
+ | Corpus parity | **3,196 / 3,196 exact** | reference |
46
+ | Encoding detector | Rust core | Python (+ mypyc/Cython) |
47
+ | Python API | `detect`, `detect_all`, `UniversalDetector` | same |
48
+ | CLI | `chardetect` | `chardetect` |
49
+ | Supported encodings | 87 registry encodings | 87 |
50
+ | License | 0BSD | 0BSD |
51
+
52
+ ## Layout
53
+
54
+ ```
55
+ chardet/ Rust core crate (library + `chardetect` binary)
56
+ src/codecs/ CPython-compatible codec validity/decoding
57
+ src/models/ models.bin / rowmax.bin parsing and bigram scoring
58
+ src/pipeline/ the 13 detection stages + orchestrator
59
+ models/ bundled model artifacts (from chardet 7)
60
+ chardet-py/ PyO3 bindings (drop-in `chardet` Python package)
61
+ scripts_generate/ Python generators for the generated data tables
62
+ scripts_compare/ parity harnesses against Python chardet 7
63
+ ```
64
+
65
+ ## Installation
66
+
67
+ ### Rust
68
+
69
+ ```console
70
+ $ cargo add chardet-rs
71
+ ```
72
+
73
+ The crate is published as `chardet-rs`; its library target is named `chardet`,
74
+ so you still `use chardet::...`:
75
+
76
+ ```rust
77
+ // Cargo.toml: chardet-rs = "0.1"
78
+ use chardet::{detect, DetectOptions};
79
+ ```
80
+
81
+ Or from a checkout:
82
+
83
+ ```console
84
+ $ cargo build --release
85
+ $ ./target/release/chardetect --version
86
+ ```
87
+
88
+ ### Python
89
+
90
+ From PyPI (distribution `chardet-rs`, import module `chardet`):
91
+
92
+ ```console
93
+ $ pip install chardet-rs
94
+ ```
95
+
96
+ Or build from a checkout:
97
+
98
+ ```console
99
+ $ python3 -m venv .venv && . .venv/bin/activate
100
+ $ pip install maturin
101
+ $ cd chardet-py && maturin build --release
102
+ $ pip install ../target/wheels/chardet_rs-*.whl
103
+ ```
104
+
105
+ > **Note:** the Python distribution is named `chardet-rs` because the name
106
+ > `chardet` on PyPI belongs to the reference project. Installing it provides
107
+ > the `chardet` import module and therefore conflicts with the reference
108
+ > `chardet` package — install one or the other in a given environment.
109
+
110
+ ## Quick Start
111
+
112
+ ### Rust
113
+
114
+ ```rust
115
+ let data = std::fs::read("unknown.txt")?;
116
+ let result = chardet::detect(&data);
117
+ println!("{:?}", result);
118
+
119
+ // All ranked candidates
120
+ let all = chardet::detect_all(&data, &chardet::DetectOptions::default())?;
121
+ ```
122
+
123
+ ### Python
124
+
125
+ ```python
126
+ import chardet
127
+
128
+ chardet.detect(b"Python is a great programming language.")
129
+ # {'encoding': 'ascii', 'confidence': 1.0, 'language': 'en', 'mime_type': 'text/plain'}
130
+
131
+ # All candidate encodings ranked by confidence
132
+ for r in chardet.detect_all("Le café est une boisson très populaire.".encode("windows-1252")):
133
+ print(r["encoding"], round(r["confidence"], 2))
134
+ ```
135
+
136
+ ### Streaming detection
137
+
138
+ ```python
139
+ from chardet import UniversalDetector
140
+
141
+ detector = UniversalDetector()
142
+ with open("unknown.txt", "rb") as f:
143
+ for line in f:
144
+ detector.feed(line)
145
+ if detector.done:
146
+ break
147
+ print(detector.close())
148
+ ```
149
+
150
+ ### Encoding era filtering
151
+
152
+ ```python
153
+ from chardet import detect_all
154
+ from chardet.enums import EncodingEra
155
+
156
+ data = "Москва является столицей Российской Федерации.".encode("windows-1251")
157
+ for r in detect_all(data, encoding_era=EncodingEra.MODERN_WEB):
158
+ print(r["encoding"], round(r["confidence"], 2))
159
+ ```
160
+
161
+ ### CLI
162
+
163
+ ```console
164
+ $ chardetect somefile.txt
165
+ somefile.txt: utf-8 with confidence 0.99
166
+
167
+ $ chardetect --minimal somefile.txt
168
+ utf-8
169
+
170
+ $ chardetect -l somefile.txt
171
+ somefile.txt: utf-8 en (English) with confidence 0.99
172
+ ```
173
+
174
+ ## How It Works
175
+
176
+ chardet-rs reproduces chardet 7's multi-stage pipeline, progressing from cheap
177
+ deterministic checks to statistical analysis:
178
+
179
+ 1. BOM detection
180
+ 2. BOM-less UTF-16/UTF-32 null-byte patterns
181
+ 3. Escape sequences (ISO-2022, HZ-GB-2312, UTF-7)
182
+ 4. Magic-number binary detection (40+ formats)
183
+ 5. Binary content detection
184
+ 6. Markup charset declarations (HTML/XML/PEP 263, including EBCDIC)
185
+ 7. ASCII check
186
+ 8. UTF-8 structural validation
187
+ 9. Byte validity filtering
188
+ 10. CJK gating
189
+ 11. Structural probing
190
+ 12. Statistical bigram scoring against the trained models
191
+ 13. Post-processing rank corrections (confusion groups, niche-Latin
192
+ demotion, KOI8-T promotion, classic-Mac line endings, decode safety)
193
+
194
+ Language detection (three tiers) and MIME type detection run alongside.
195
+
196
+ ## Parity Testing
197
+
198
+ The port is validated against Python chardet 7:
199
+
200
+ ```console
201
+ $ git clone --depth 1 https://github.com/chardet/test-data tests/data
202
+ $ CHARDET_SRC=/path/to/chardet/src python3 scripts_compare/full_corpus.py tests/data
203
+ mime match: 3196/3196 (100.00%)
204
+ encoding match: 3196/3196 (100.00%)
205
+ exact match: 3196/3196 (100.00%)
206
+ ```
207
+
208
+ Harnesses live in `scripts_compare/`:
209
+
210
+ - `parity.py` — hand-written multilingual samples.
211
+ - `edge_parity.py` — BOMs, markup declarations, EBCDIC, niche-Latin/KOI8-T
212
+ arbitration, CR line endings, truncation at every length, magic numbers.
213
+ - `fuzz.py` — randomized/structured byte sequences.
214
+ - `full_corpus.py` — the full `chardet/test-data` corpus.
215
+ - `api_parity.py` — `detect_all` / `UniversalDetector`.
216
+
217
+ CI runs the Rust tests, builds the Python wheel, and compares against the
218
+ reference `chardet` wheel from PyPI.
219
+
220
+ ## Regenerating data tables
221
+
222
+ The generated Rust tables (single-byte codec maps, DBCS validity tables,
223
+ Unicode categories, registry and CPython aliases) are produced from CPython so
224
+ the Rust codecs match Python's behavior exactly:
225
+
226
+ ```console
227
+ $ python3 scripts_generate/gen_registry.py > chardet/src/registry_data.rs
228
+ $ python3 scripts_generate/gen_codec_tables.py > chardet/src/codecs/sbcs_data.rs
229
+ $ python3 scripts_generate/gen_dbcs_tables.py > chardet/src/codecs/dbcs.bin
230
+ $ python3 scripts_generate/gen_categories.py > chardet/src/codecs/categories_data.rs
231
+ ```
232
+
233
+ ## Supported Encodings
234
+
235
+ Full chardet 7 coverage, including Windows code pages, ISO-8859 family, Mac,
236
+ KOI8, DOS, mainframe EBCDIC, CJK (CP932/CP949/GB18030/Big5/EUC-JP/EUC-KR/Johab
237
+ and the ISO-2022/HZ escape encodings), and the Unicode family.
238
+
239
+ ## Project History
240
+
241
+ chardet was created by [Mark Pilgrim](https://en.wikipedia.org/wiki/Mark_Pilgrim)
242
+ in 2006 as a Python port of [Mozilla's universal charset detection
243
+ library](https://www-archive.mozilla.org/projects/intl/chardet.html). After he
244
+ deleted his online accounts in 2011, the project was continued by David Cramer,
245
+ Erik Rose, Toshio Kuratomi, Ian Cordasco, and Dan Blanchard. In 2026 Dan
246
+ Blanchard rewrote chardet as a ground-up 0BSD-licensed implementation, released
247
+ as chardet 7.
248
+
249
+ **chardet-rs** is an independent Rust rewrite of chardet 7. It reuses chardet
250
+ 7's trained model artifacts and mirrors its pipeline, so the detection results
251
+ match, while the implementation is native Rust. All credit for the original
252
+ algorithm, models, and training data belongs to the chardet authors listed
253
+ above.
254
+
255
+ ## License
256
+
257
+ 0BSD — same as chardet 7. See [LICENSE](LICENSE).
258
+