{"id":32167025,"url":"https://github.com/ryochin/charset_detect","last_synced_at":"2025-10-21T15:18:34.023Z","repository":{"id":214715920,"uuid":"737189483","full_name":"ryochin/charset_detect","owner":"ryochin","description":"Guess character encoding for Elixir","archived":false,"fork":false,"pushed_at":"2025-03-19T01:47:18.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-21T23:23:22.353Z","etag":null,"topics":["character","charset-detection","elixir","encoding"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/charset_detect","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryochin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-30T05:48:29.000Z","updated_at":"2025-03-19T01:47:21.000Z","dependencies_parsed_at":"2024-12-01T16:47:50.784Z","dependency_job_id":null,"html_url":"https://github.com/ryochin/charset_detect","commit_stats":null,"previous_names":["ryochin/charset_detect"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ryochin/charset_detect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryochin%2Fcharset_detect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryochin%2Fcharset_detect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryochin%2Fcharset_detect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryochin%2Fcharset_detect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryochin","download_url":"https://codeload.github.com/ryochin/charset_detect/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryochin%2Fcharset_detect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280283423,"owners_count":26304091,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["character","charset-detection","elixir","encoding"],"created_at":"2025-10-21T15:18:31.292Z","updated_at":"2025-10-21T15:18:34.018Z","avatar_url":"https://github.com/ryochin.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"🌏 CharsetDetect: Guess character encoding\n==========================================\n\n[![Hex.pm](https://img.shields.io/hexpm/v/charset_detect.svg)](https://hex.pm/packages/charset_detect)\n[![Hexdocs.pm](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/charset_detect/)\n[![Hex.pm](https://img.shields.io/hexpm/dt/charset_detect.svg)](https://hex.pm/packages/charset_detect)\n[![License](https://img.shields.io/hexpm/l/charset_detect.svg)](https://github.com/ryochin/charset_detect/blob/main/LICENSE)\n\nCharsetDetect is a simple wrapper around the [chardetng](https://crates.io/crates/chardetng) crate.\n\nUsage\n-----\n\nGuess the encoding of a string:\n\n```elixir\niex\u003e File.read!(\"test/assets/sjis.txt\") |\u003e CharsetDetect.guess\n{:ok, \"Shift_JIS\"}\n\niex\u003e File.read!(\"test/assets/big5.txt\") |\u003e CharsetDetect.guess!\n\"Big5\"\n```\n\nYou might consider minimizing additional memory consumption.\n\n```elixir\niex\u003e \"... (long text) ...\" |\u003e String.slice(0, 1024) |\u003e CharsetDetect.guess\n```\n\n\u003e [!NOTE]\n\u003e An ASCII string, including an empty string, will result in a `UTF-8` encoding rather than `ASCII`.\n\n```elixir\niex\u003e \"hello world\" |\u003e CharsetDetect.guess\n{:ok, \"UTF-8\"}\n```\n\nStrategies for implementing a conversion function\n-------------------------------------------------\n\nYou can achieve conversion to any desired encoding using [iconv](https://hex.pm/packages/iconv).\n\n```elixir\ndefmodule Converter do\n  @spec convert(binary, String.t()) :: {:ok, binary} | {:error, String.t()}\n  def convert(text, to_encoding \\\\ \"UTF-8\") when is_binary(text) do\n    case text |\u003e String.slice(0, 1024) |\u003e CharsetDetect.guess do\n      {:ok, ^to_encoding} -\u003e\n        {:ok, text}\n      {:ok, encoding} -\u003e\n        try do\n          {:ok, :iconv.convert(encoding, to_encoding, text)}\n        rescue\n          e in ArgumentError -\u003e {:error, inspect(e)}\n        end\n      {:error, reason} -\u003e\n        {:error, reason}\n    end\n  end\n\n  def convert(_, _), do: {:error, \"not a string\"}\nend\n```\n```elixir\niex\u003e File.read!(\"test/assets/big5.txt\") |\u003e Converter.convert\n{:ok, \"大五碼是繁体中文（正體中文）社群最常用的電腦漢字字符集標準。\\n\"}    # UTF-8\n```\n\nInstallation\n------------\n\nThe package can be installed by adding `charset_detect` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:charset_detect, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\nThen, run `mix deps.get`.\n\nDevelopment\n-----------\n\n### Prerequisites\n\n\u003e [!NOTE]\n\u003e This library requires the [Rust](https://www.rust-lang.org/) Toolchain for compilation.\n\nFollow the instructions at [www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install) to install Rust.\n\nVerify the installation by checking the `cargo` command version:\n\n```sh\ncargo --version\n# Should output something like: cargo 1.82.0 (8f40fc59f 2024-08-21)\n```\n\nThen, set the `RUSTLER_PRECOMPILATION_EXAMPLE_BUILD` environment variable to ensure that local sources are compiled instead of downloading a precompiled library file.\n\n```sh\nRUSTLER_PRECOMPILATION_EXAMPLE_BUILD=1 mix compile\n```\n\nLicense\n-------\n\nThe MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryochin%2Fcharset_detect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryochin%2Fcharset_detect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryochin%2Fcharset_detect/lists"}