{"id":22705722,"url":"https://github.com/hey-red/mime","last_synced_at":"2025-04-05T08:05:53.755Z","repository":{"id":41812726,"uuid":"69294049","full_name":"hey-red/Mime","owner":"hey-red","description":".NET wrapper for libmagic","archived":false,"fork":false,"pushed_at":"2023-12-05T13:15:25.000Z","size":4355,"stargazers_count":83,"open_issues_count":10,"forks_count":21,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-29T18:42:02.435Z","etag":null,"topics":["c-sharp","dotnet","file","libmagic","mime","mime-types","netstandard"],"latest_commit_sha":null,"homepage":"","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/hey-red.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}},"created_at":"2016-09-26T21:23:12.000Z","updated_at":"2024-10-07T13:30:39.000Z","dependencies_parsed_at":"2023-12-18T11:01:11.457Z","dependency_job_id":"445e0e0c-570b-41fd-a986-1462d35d8826","html_url":"https://github.com/hey-red/Mime","commit_stats":{"total_commits":188,"total_committers":9,"mean_commits":20.88888888888889,"dds":"0.18617021276595747","last_synced_commit":"b0582324592c574fda00e0705e4ed036fc918f8e"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hey-red%2FMime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hey-red%2FMime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hey-red%2FMime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hey-red%2FMime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hey-red","download_url":"https://codeload.github.com/hey-red/Mime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305933,"owners_count":20917208,"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","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":["c-sharp","dotnet","file","libmagic","mime","mime-types","netstandard"],"created_at":"2024-12-10T09:12:42.992Z","updated_at":"2025-04-05T08:05:53.735Z","avatar_url":"https://github.com/hey-red.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mime\n.NET wrapper for libmagic\n\n[![NuGet](https://img.shields.io/nuget/v/Mime.svg)](https://www.nuget.org/packages/Mime)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/hey-red/Markdown/blob/master/LICENSE)\n\n## Install\nvia [NuGet](https://www.nuget.org/packages/Mime):\n```\nPM\u003e Install-Package Mime\n```\n\n## Requirements\nSupported runtimes: \n* linux-musl-x64\n* linux-x64\n* osx-arm64(tested on macOS 13 Ventura)\n* osx-x64\n* win-x64\n\n## Basic usage\n```C#\nusing HeyRed.Mime;\n\n// (Optionally) You can set path to magic database file manually.\nMimeGuesser.MagicFilePath = \"/path/to/magic.mgc\";\n\n// Guess mime type of file(overloaded method takes byte array or stream as arg.)\nMimeGuesser.GuessMimeType(\"path/to/file\"); //=\u003e image/jpeg\n\n// Get extension of file(overloaded method takes byte array or stream as arg.)\nMimeGuesser.GuessExtension(\"path/to/file\"); //=\u003e jpeg\n\n// Get mime type and extension of file(overloaded method takes byte array or stream as arg.)\nMimeGuesser.GuessFileType(\"path/to/file\"); //=\u003e FileType\n```\n\n## Advanced\nWant more than just the mime type? Use the Magic class:\n```C#\nstring calc = @\"C:\\Windows\\System32\\calc.exe\";\nusing var magic = new Magic(MagicOpenFlags.MAGIC_NONE);\nmagic.Read(calc); //=\u003e PE32+ executable (GUI) x86-64, for MS Windows\n\n// Check encoding:\nstring textFile = @\"F:\\Temp\\file.txt\";\nusing var magic = new Magic(MagicOpenFlags.MAGIC_MIME_ENCODING);\nmagic.Read(textFile); //=\u003e Output: utf-8\n```\nAlso, we can combine flags with \"|\" operator.\nSee all [flags](src/Mime/MagicOpenFlags.cs) for more info.\n\n## Remarks\n- The Magic class is not thread safe, but if you use different instances on different threads it seems to work fine.\n- The MimeGuesser is thread safe, since it generates a new instance of Magic class on each use.\n\n## Possible problems\n| Exception | Solution |\n| :--- | :--- |\n| DllNotFoundException | Make sure that your `bin` folder contains runtimes directory. If you publishing platform dependent app, then `bin` should be contains `libmagic-1`(.dll, .so or .dylib) and `magic.mgc` files. |\n| BadImageFormatException | Make sure when you target the `AnyCPU` platform the `Prefer 32-bit` option is unchecked. Or try to target `x64/arm64` instead. |\n| MagicException: Could not find any valid magic files! | Make sure your magic.mgc file contains in one of /runtimes/ subdirs or along with libmagic-1.[dll\\|lib\\|dylib]. Or set path to custom database as described in [basic usage](https://github.com/hey-red/Mime#basic-usage) |\n\n## License\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhey-red%2Fmime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhey-red%2Fmime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhey-red%2Fmime/lists"}