{"id":16488487,"url":"https://github.com/stellarbear/mimemagicsharp","last_synced_at":"2025-08-15T21:35:52.312Z","repository":{"id":31694133,"uuid":"131148520","full_name":"stellarbear/MimeMagicSharp","owner":"stellarbear","description":"Detects MIME type based on file content or file extension","archived":false,"fork":false,"pushed_at":"2022-12-08T01:05:03.000Z","size":667,"stargazers_count":6,"open_issues_count":1,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-27T13:31:39.073Z","etag":null,"topics":["csharp","detection","json","magic","mime","mime-database","mime-detector","mime-parser","mime-type","net"],"latest_commit_sha":null,"homepage":null,"language":"C#","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/stellarbear.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}},"created_at":"2018-04-26T11:54:30.000Z","updated_at":"2024-04-09T18:22:21.000Z","dependencies_parsed_at":"2023-01-14T19:34:45.284Z","dependency_job_id":null,"html_url":"https://github.com/stellarbear/MimeMagicSharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stellarbear/MimeMagicSharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarbear%2FMimeMagicSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarbear%2FMimeMagicSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarbear%2FMimeMagicSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarbear%2FMimeMagicSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stellarbear","download_url":"https://codeload.github.com/stellarbear/MimeMagicSharp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stellarbear%2FMimeMagicSharp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270631876,"owners_count":24619384,"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-08-15T02:00:12.559Z","response_time":110,"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":["csharp","detection","json","magic","mime","mime-database","mime-detector","mime-parser","mime-type","net"],"created_at":"2024-10-11T13:39:03.345Z","updated_at":"2025-08-15T21:35:52.289Z","avatar_url":"https://github.com/stellarbear.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MimeMagicSharp\nDetects MIME type based on file content or file extension. [Nuget package](https://www.nuget.org/packages/MimeMagicSharp/) is available. Sample files are included.\n\n## Description\nThis project was originally based on parsing  **/usr/share/mime/magic** (Kali Linux) file (**mime database**). Location may differ. More information about this file structure could be found [here](https://developer.gnome.org/shared-mime-info-spec/) (\"the magic files\" section). \n\nThis file contains mime type definitions with several rule sets, which are applied iteratively to the given file's content to guess mime type(s).\n\nOriginal file's format (**old**) is hard to modify according to your needs. I decided to move on to json file format (**new**) with similary capabilities and some new features. New format could be easily modified and updated with new rule sets and mime type definitions.\n\nBoth database formats are supported. Conversion from the old to the new database format is supported. Detection by extension can be used only with new file format. Template original and json files **will be** included soon.\n\n## Structure\nEach MIME definition contains a list of rule sets. Each rule set contains an hierarchical list of rules. Rule set pseudocode:\n```C#\n//  Level 0 rules: Rule 0\n//  Level 1 rules: Rule 1, Rule 2, Rule 3\n//  Level 2 rules: Rule 4\n//  Level 3 rules: Rule 5, Rule 6\n//\t...\n```\nWhen this ruleset is applied, result will be calculated in the following manner:\n```C#\n//  Result (boolean) = 0 \u0026\u0026 (1 || 2 || 3) \u0026\u0026 4 \u0026\u0026 (5 || 6)...\n```\nRule example:\n```C#\n\"Name\": \"application/x-deb\",\n\"Description\": \"Debian package\",\n\"Extensions\": [\"deb\"],\n\"RuleSet\": [\n    {\n    \"Rule\": [\n        {\n        \"Level\": 0,\n        \"Offset\": 0,\n        \"Range\": 0,\n        \"Data\": \"213C617263683E\",\n        \"DataUTF8\": \"!\u003carch\u003e\"\n        },\n        {\n        \"Level\": 1,\n        \"Offset\": 8,\n        \"Range\": 0,\n        \"Data\": \"64656269616E\",\n        \"DataUTF8\": \"debian\"\n        }\n    ]\n    }, \"Rule\":[...\n    ]...\n```\n- **Level**. Explained earlier.\n- **Offset**. Seek start position\n- **Range**. Seek interval (0 means fixed position)\n- **Data**. Data to seek in hex format\n- **Description** and **DataUTF8** are for visual purposes only.\n\n## Usage\n```C#\n//\tDatabase File (new or old)\nstring MagicFile = Path.Combine(Environment.CurrentDirectory, \"magic\");\n\nusing (MimeMagicSharp.MimeMagicSharp ms = new MimeMagicSharp.MimeMagicSharp(MimeMagicSharp.EMagicFileType.Json, MagicFile))\n{\n   try\n   {\n\tforeach (MimeTypeGuess mimeTypeGuess in ms.AssumeMimeType(EMimeTypeBy.Content,\n                    \tPath.Combine(Environment.CurrentDirectory, \"Newtonsoft.Json.xml\")))\n\t{\n\t\t//  Iterate over results\n\t}\n    }\n    catch (Exception Ex)\n    { \n       //   Handle errors\n    }\n}\n```\nConvertion from original (old) format to json (new) is supported \n```C#\nMimeMagicSharp.MimeMagicSharp.ConvertFromOriginalToJson(\"magic_original\", \"magic_json_convert_test\", out string ConvertError);\n```\n\n## Limitations\nOnly first 4096 bytes of file are read during mime detection procedure. You can extend this limit in source code easily.\n\n## Other\nBuild in vs 2017\n\nYou can use or modify the sources however you want\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstellarbear%2Fmimemagicsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstellarbear%2Fmimemagicsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstellarbear%2Fmimemagicsharp/lists"}