{"id":51014498,"url":"https://github.com/gechandesu/mediatypes","last_synced_at":"2026-06-21T08:31:30.508Z","repository":{"id":358499259,"uuid":"1241636358","full_name":"gechandesu/mediatypes","owner":"gechandesu","description":"Manipulating media (MIME) types","archived":false,"fork":false,"pushed_at":"2026-05-17T16:34:55.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-17T18:46:18.217Z","etag":null,"topics":["mime","mime-types","vlang","vlang-module","vlang-package"],"latest_commit_sha":null,"homepage":"https://gechandesu.github.io/mediatypes/","language":"V","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/gechandesu.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-17T16:25:48.000Z","updated_at":"2026-05-17T16:37:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/gechandesu/mediatypes","commit_stats":null,"previous_names":["gechandesu/mediatypes"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/gechandesu/mediatypes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gechandesu%2Fmediatypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gechandesu%2Fmediatypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gechandesu%2Fmediatypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gechandesu%2Fmediatypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gechandesu","download_url":"https://codeload.github.com/gechandesu/mediatypes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gechandesu%2Fmediatypes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34603546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"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":["mime","mime-types","vlang","vlang-module","vlang-package"],"created_at":"2026-06-21T08:31:29.748Z","updated_at":"2026-06-21T08:31:30.503Z","avatar_url":"https://github.com/gechandesu.png","language":"V","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Media Types\n\n`mediatypes` module allows you to manipulate media types, also known as MIME\ntypes.\n\nApplications can manage types through the `MediaTypeDatabase` abstraction.\nTypes can be pre-defined in the application, and additional arbitrary\n(including custom) types can be loaded at runtime from memory or from files\nthat adhere to the /etc/mime.types format.\n\nSee also:\n\n* https://en.wikipedia.org/wiki/MIME\n* https://wiki.debian.org/MIME/etc/mime.types\n* https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types\n* https://www.iana.org/assignments/media-types/media-types.xhtml\n\n## Usage\n\nFor example load the system-wide media types mapping file /etc/mime.types and\ntry to detect the files media type by extension:\n\n```v\nimport os\nimport mediatypes\n\nfn main() {\n\tmut mime_types_file := os.open('/etc/mime.types')!\n\tdefer {\n\t\tmime_types_file.close()\n\t}\n\n\tmime_types := mediatypes.load(mut mime_types_file)\n\n\ttest_data := {\n\t\t'style.css':     'text/css'\n\t\t'image.png':     'image/png'\n\t\t'manifest.json': 'application/json'\n\t}\n\n\tfor file_name, expected_type in test_data {\n\t\tmime_type := mime_types.lookup(os.file_ext(file_name))\n\t\tdump(mime_type)\n\t\tassert mime_type.name() == expected_type\n\t}\n}\n```\n\nYou can add any custom media types and associate media types with file\nextensions as you need by manipulating the `MediaTypeDatabase` object:\n\n```v ignore\nmut mime_types := mediatypes.new() // or use mediatypes.load()\nmime_types.add(mediatypes.MediaType{\n\ttype_name:  'application'\n\tsubtype:    'my-custom-type'\n\textensions: ['custom']\n})\n```\n\n## Embedding media types database into application\n\nTo add built-in support for media types to an application, you need to define\nconstants with type data in the application's source code. For large lists of\ntypes, this is too tedious, so a special code generator script is included\nwith the `mediatypes` lib.\n\nUse embed_media_types.vsh to get the `.v` file content with embedded media\ntypes database.\n\nThe following command will print the .v file content to the standard output:\n\n```\nv run embed_media_types.vsh\n```\n\nBy default script will download the\n[mime.types](https://github.com/apache/httpd/blob/trunk/docs/conf/mime.types)\nfile maintained by Apache HTTP Server project.\n\nRun `v run embed_media_types.vsh -help` to see available script options.\n\nembed_media_types.vsh script skips type definitions for which a list of file\nextensions is not specified.\n\nThe script output is not formatted be default. Use `v fmt` to format the\ngenerated file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgechandesu%2Fmediatypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgechandesu%2Fmediatypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgechandesu%2Fmediatypes/lists"}