# File encoding detection library

**URL:** <https://forum.elixirforum.com/t/file-encoding-detection-library/34972>\
**Category:** Questions\
**Tags:** csv\
**Created:** [October 16, 2020, 7:53am UTC](https://forum.elixirforum.com/t/file-encoding-detection-library/34972 "2020-10-16T07:53:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [October 16, 2020, 9:23am UTC](https://forum.elixirforum.com/t/file-encoding-detection-library/34972/5 "2020-10-16T09:23:02Z")

</div>

There is no way to get what you want.

Ask your clients to upload using a specified charset _only_.

If you see the single byte `0xC4`, that _could_ be a latin-1 encoded `Ä`, though in ISO-8859-5 (kyrillic) it would be as valid as with latin-1 though encoding a different character, the `Ф`.

Therefore it is _impossible_ to detect the encoding without knowing the content in advance.

What you describe from the other languages, is usually a very dumb heuristic.

1. Check if the input is valid UTF-8/16/32 by corresponding validators, perhaps even helped by a BOM
2. If not, fall back to a single byte encoding derived from the hosts local settings

---

_[View the full topic](https://forum.elixirforum.com/t/file-encoding-detection-library/34972)._
