{"id":13764065,"url":"https://github.com/zRedShift/mimemagic","last_synced_at":"2025-05-10T17:31:34.498Z","repository":{"id":45454466,"uuid":"152620511","full_name":"zRedShift/mimemagic","owner":"zRedShift","description":"Powerful and versatile MIME sniffing package using pre-compiled glob patterns, magic number signatures, XML document namespaces, and tree magic for mounted volumes, generated from the XDG shared-mime-info database.","archived":false,"fork":false,"pushed_at":"2023-10-11T23:23:51.000Z","size":15556,"stargazers_count":100,"open_issues_count":6,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T13:51:15.259Z","etag":null,"topics":["detection","extension","filetype","freedesktop","go","golang","magic-numbers","mime","mime-database","mime-types","sniffing","xdg"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zRedShift.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":"2018-10-11T16:12:54.000Z","updated_at":"2025-02-16T02:26:56.000Z","dependencies_parsed_at":"2024-06-18T17:01:53.680Z","dependency_job_id":"cfb02372-5e66-40cc-8b68-db8f196da6cf","html_url":"https://github.com/zRedShift/mimemagic","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":0.3076923076923077,"last_synced_commit":"5028b726e7cdb453d7bccb8c660ab9f75c488c79"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zRedShift%2Fmimemagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zRedShift%2Fmimemagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zRedShift%2Fmimemagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zRedShift%2Fmimemagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zRedShift","download_url":"https://codeload.github.com/zRedShift/mimemagic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253453316,"owners_count":21911076,"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":["detection","extension","filetype","freedesktop","go","golang","magic-numbers","mime","mime-database","mime-types","sniffing","xdg"],"created_at":"2024-08-03T15:01:11.700Z","updated_at":"2025-05-10T17:31:29.487Z","avatar_url":"https://github.com/zRedShift.png","language":"Go","funding_links":[],"categories":["公用事业公司","Utilities","工具库","工具库`可以提升效率的通用代码库和工具`","Utility"],"sub_categories":["实用程序/Miscellaneous","HTTP Clients","Utility/Miscellaneous","查询语","Fail injection"],"readme":"mimemagic\n=========\n[![GoDoc](https://godoc.org/github.com/zRedShift/mimemagic?status.svg)](https://godoc.org/github.com/zRedShift/mimemagic)\n[![Build Status](https://travis-ci.org/zRedShift/mimemagic.svg?branch=master)](https://travis-ci.org/zRedShift/mimemagic)\n[![Codecov](https://codecov.io/gh/zRedShift/mimemagic/branch/master/graph/badge.svg)](https://codecov.io/gh/zRedShift/mimemagic/)\n[![Go Report Card](https://goreportcard.com/badge/github.com/zRedShift/mimemagic)](https://goreportcard.com/report/github.com/zRedShift/mimemagic)\n\nPowerful and versatile MIME sniffing package using pre-compiled glob patterns, magic number signatures, xml document\nnamespaces, and tree magic for mounted volumes, generated from the XDG shared-mime-info database.\n\n## License\n\nThe generated code in `magicsigs.go`, `globs.go`, `treemagicsigs.go`, `namespaces.go` \nand `mediatypes.go` makes this a derivative work of `shared-mime-info`, and therefore falls under the\n`GPL-2.0-or-later` license. See the [discussion](https://github.com/zRedShift/mimemagic/issues/4).\n\nFor an MIT licensed branch with the generated code  removed, please see \n[this](https://github.com/zRedShift/mimemagic/tree/MIT). Providing a hypothetical permissively licensed\nfreedesktop.org.xml file for parsing is still required, to redistribute the compiled executable with that license, \nhowever.\n\n## Features\n\n- All in native go, no outside dependencies/C library bindings\n- 1003 MIME types, with a description, an acronym (where available), common aliases, extensions, icons, and \nsubclasses\n- 493 magic signature tests (comprising of 1147 individual patterns), featuring range searches and bit masks, as per\nthe xdg specification\n- 1099 glob patterns, for filename-based matching\n- 11 Tree Magic signatures and 28 XML namespace/local name pairs, offered for completeness' sake.\n- Included is the xml file parser to generate your own MIME definitions\n- Also included is a CLI based on this library that is fully featured and blazing-fast, beating the native 'file'\nand KDE's 'kmimetypefinder' in performance\n- Cross-platform support\n\n## Installation\n\nThe library:\n```bash\ngo get github.com/zRedShift/mimemagic/v2\n```\nThe CLI:\n```bash\ngo get github.com/zRedShift/mimemagic/v2/cmd/mimemagic\n```\n\n## API\n\nSee the [Godoc](https://godoc.org/github.com/zRedShift/mimemagic) reference, and cmd/mimemagic for an example\nimplementation.\n\n## Usage\n\nThe library:\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/zRedShift/mimemagic/v2\"\n\t\"strings\"\n)\n\nfunc main() {\n\t// Ignoring Read errors that might arise\n\tmimeType, _ := mimemagic.MatchFilePath(\"sample.svgz\", -1)\n\n\t// image/svg+xml-compressed\n\tfmt.Println(mimeType.MediaType())\n\n\t// compressed SVG image\n\tfmt.Println(mimeType.Comment)\n\n\t// SVG (Scalable Vector Graphics)\n\tfmt.Printf(\"%s (%s)\\n\", mimeType.Acronym, mimeType.ExpandedAcronym)\n\n\t// application/gzip\n\tfmt.Println(strings.Join(mimeType.SubClassOf, \", \"))\n\n\t// .svgz\n\tfmt.Println(strings.Join(mimeType.Extensions, \", \"))\n\n\t// This is an image.\n\tswitch mimeType.Media {\n\tcase \"image\":\n\t\tfmt.Println(\"This is an image.\")\n\tcase \"video\":\n\t\tfmt.Println(\"This is a video file.\")\n\tcase \"audio\":\n\t\tfmt.Println(\"This is an audio file.\")\n\tcase \"application\":\n\t\tfmt.Println(\"This is an application.\")\n\tdefault:\n\t\tfmt.Printf(\"This is a(n) %s.\", mimeType.Media)\n\t}\n\n\t// true\n\tfmt.Println(mimeType.IsExtension(\".svgz\"))\n}\n```\nThe CLI:\n```\nUsage: mimemagic [options] \u003cfile\u003e ...\nDetermines the MIME type of the given file(s).\n\nOptions:\n  -c    Determine the MIME type of the file(s) using only its content.\n  -f    Determine the MIME type of the file(s) using only the file name. Does\n        not check for the file's existence. The -c\n         flag takes precedence.\n  -i    Output the MIME type in a human readable format.\n  -l int\n        The number of bytes from the beginning of the file mimemagic will\n        examine. Reads the entire file if set to a negative value. By default\n        mimemagic will only read the first 512 from stdin, however setting this\n        flag to a non-default negative value will override this. (default -1)\n  -t    Determine the MIME type of the directory/mounted volume using tree\n        magic. Can't be used in conjunction with with -c, -f or -x.\n  -x    Determine the MIME type of the xml file(s) using the local names and\n        namespaces within. Can't be used in conjunction with -c, -f or -t.\n\nArguments:\n  file\n        The file(s) to test. '-' to read from stdin. If '-' is set, all other\n        inputs will be ignored.\n\nExamples:\n  $ mimemagic -c sample.svgz\n    \tapplication/gzip\n  $ mimemagic *.svg*\n    \tOlympic_rings_with_transparent_rims.svg: image/svg+xml\n    \tPiano.svg.png: image/png\n    \tRAID_5.svg: image/svg+xml\n    \tsample.svgz: image/svg+xml-compressed\n  $ cat /dev/urandom | mimemagic -\n    \tapplication/octet-stream\n  $ ls software; mimemagic -i -t software/\n    \tautorun\n    \tUNIX software\n```\n\n## Benchmarks\n\nSee [Benchmarks](https://github.com/zRedShift/mimemagic/blob/master/benchmarks.txt). For Match(), the average across \nover 400 completely different files (representing a unique MIME type each) is 13 ± 7 μs/op. For MatchGlob() it's 900\n± 200 ns/op, and for 12 ± 7 μs/op MatchMagic().\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FzRedShift%2Fmimemagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FzRedShift%2Fmimemagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FzRedShift%2Fmimemagic/lists"}