{"id":31544737,"url":"https://github.com/jaywcjlove/filetype","last_synced_at":"2025-10-04T13:50:30.029Z","repository":{"id":309925575,"uuid":"1038048962","full_name":"jaywcjlove/FileType","owner":"jaywcjlove","description":"This tool checks a file’s MIME type using magic bytes and can retrieve the file extension from the MIME type.  ","archived":false,"fork":false,"pushed_at":"2025-09-18T14:43:36.000Z","size":48,"stargazers_count":29,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-01T06:36:38.108Z","etag":null,"topics":["file","file-type","swift","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/jaywcjlove.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"ko_fi":"jaywcjlove","buy_me_a_coffee":"jaywcjlove","custom":["https://www.paypal.me/kennyiseeyou","https://jaywcjlove.github.io/#/sponsor"]}},"created_at":"2025-08-14T14:35:24.000Z","updated_at":"2025-09-18T14:43:39.000Z","dependencies_parsed_at":"2025-10-02T13:02:39.068Z","dependency_job_id":null,"html_url":"https://github.com/jaywcjlove/FileType","commit_stats":null,"previous_names":["jaywcjlove/filetype"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/jaywcjlove/FileType","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaywcjlove%2FFileType","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaywcjlove%2FFileType/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaywcjlove%2FFileType/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaywcjlove%2FFileType/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaywcjlove","download_url":"https://codeload.github.com/jaywcjlove/FileType/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaywcjlove%2FFileType/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278322172,"owners_count":25967873,"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-04T02:00:05.491Z","response_time":63,"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":["file","file-type","swift","swiftui"],"created_at":"2025-10-04T13:50:25.138Z","updated_at":"2025-10-04T13:50:30.013Z","avatar_url":"https://github.com/jaywcjlove.png","language":"Swift","funding_links":["https://ko-fi.com/jaywcjlove","https://buymeacoffee.com/jaywcjlove","https://www.paypal.me/kennyiseeyou","https://jaywcjlove.github.io/#/sponsor"],"categories":[],"sub_categories":[],"readme":"\u003cdiv markdown=\"1\"\u003e\n  \u003csup\u003eUsing \u003ca href=\"https://wangchujiang.com/#/app\" target=\"_blank\"\u003emy app\u003c/a\u003e is also a way to \u003ca href=\"https://wangchujiang.com/#/sponsor\" target=\"_blank\"\u003esupport\u003c/a\u003e me:\u003c/sup\u003e\n  \u003cbr\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/VidCrop/6752624705\" title=\"VidCrop for macOS\"\u003e\u003cimg align=\"center\" alt=\"VidCrop\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/91d2b281-271a-4107-9ef6-f3b11bd6dbac\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/Vidwall/6747587746\" title=\"Vidwall for macOS\"\u003e\u003cimg align=\"center\" alt=\"Vidwall\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/7b5df70a-ed91-4d4b-85be-f00e60a09ce9\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://wangchujiang.com/mousio-hint/\" title=\"Mousio Hint for macOS\"\u003e\u003cimg align=\"center\" alt=\"Mousio Hint\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/3c0af128-0cef-44e5-a8db-4741dc5a6690\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6746747327\" title=\"Mousio for macOS\"\u003e\u003cimg align=\"center\" alt=\"Mousio\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/9edf61ff-5a6c-4676-9cc2-8fd3c1ad0dfb\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6745227444\" title=\"Musicer for macOS\"\u003e\u003cimg align=\"center\" alt=\"Musicer\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/b7abfba8-88ff-4c86-a125-43073d5aef22\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6743841447\" title=\"Audioer for macOS\"\u003e\u003cimg align=\"center\" alt=\"Audioer\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/7a836865-8c90-4119-87bc-19e06a76c957\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6744690194\" title=\"FileSentinel for macOS\"\u003e\u003cimg align=\"center\" alt=\"FileSentinel\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/28bce2cc-290e-45bf-9068-585ff6ecafe9\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6743495172\" title=\"FocusCursor for macOS\"\u003e\u003cimg align=\"center\" alt=\"FocusCursor\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/d543668a-737b-4853-a6bb-eaa269e69836\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6742680573\" title=\"Videoer for macOS\"\u003e\u003cimg align=\"center\" alt=\"Videoer\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/10ffb0f1-0625-40d6-93f1-2c2496592595\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6740425504\" title=\"KeyClicker for macOS\"\u003e\u003cimg align=\"center\" alt=\"KeyClicker\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/5a19fcb9-cb81-4855-b4ea-31c604d9612a\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6739052447\" title=\"DayBar for macOS\"\u003e\u003cimg align=\"center\" alt=\"DayBar\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/771b608d-594c-492d-8532-d9231e383f5b\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6739444407\" title=\"Iconed for macOS\"\u003e\u003cimg align=\"center\" alt=\"Iconed\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/8a35dc7b-4faf-4e2a-9311-f66d6844a896\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6737160756\" title=\"RightMenu Master for macOS\"\u003e\u003cimg align=\"center\" alt=\"RightMenu Master\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/39a76541-71bf-4de7-a01c-c62f0557dff5\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6723903021\" title=\"Paste Quick for macOS\"\u003e\u003cimg align=\"center\" alt=\"Quick RSS\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/bdaad5b7-9810-44ce-8f17-8410864465d2\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6670696072\" title=\"Quick RSS for macOS/iOS\"\u003e\u003cimg align=\"center\" alt=\"Quick RSS\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/374106b5-a448-4d1d-9ccb-b04b6bc681ed\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6670167443\" title=\"Web Serve for macOS\"\u003e\u003cimg align=\"center\" alt=\"Web Serve\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/e1d9f76f-0f3d-4ba5-8a15-253ee173bb1c\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6503953628\" title=\"Copybook Generator for macOS/iOS\"\u003e\u003cimg align=\"center\" alt=\"Copybook Generator\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/b90e42ff-158b-4534-82ca-5898fd0e8d73\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6471227008\" title=\"DevTutor for macOS/iOS\"\u003e\u003cimg align=\"center\" alt=\"DevTutor for SwiftUI\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/f15c154d-0192-48eb-8e0e-9e245ffd974a\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6479819388\" title=\"RegexMate for macOS/iOS\"\u003e\u003cimg align=\"center\" alt=\"RegexMate\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/aabe5aa9-9a96-4390-8bed-c3e4023d0dea\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6479194014\" title=\"Time Passage for macOS/iOS\"\u003e\u003cimg align=\"center\" alt=\"Time Passage\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/time-passage/assets/1680273/6f30e429-e6f3-4dbe-9921-a5effe2a05e9\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6478772538\" title=\"IconizeFolder for macOS\"\u003e\u003cimg align=\"center\" alt=\"Iconize Folder\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/fa9d8b9c-1e51-4ded-877c-fa5b21c47220\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6478511402\" title=\"Textsound Saver for macOS/iOS\"\u003e\u003cimg align=\"center\" alt=\"Textsound Saver\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/0595e842-980b-4574-8891-a8ba853a08be\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6476924627\" title=\"Create Custom Symbols for macOS\"\u003e\u003cimg align=\"center\" alt=\"Create Custom Symbols\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/8cd022ce-a3f1-4e89-b7c6-6fbd0d4db77c\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6476452351\" title=\"DevHub for macOS\"\u003e\u003cimg align=\"center\" alt=\"DevHub\" height=\"52\" width=\"52\" src=\"https://github.com/user-attachments/assets/4a44a4fd-67ce-430b-af0a-72f18feaa47d\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6476400184\" title=\"Resume Revise for macOS\"\u003e\u003cimg align=\"center\" alt=\"Resume Revise\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/c9954a20-1905-48de-bdf8-d71837974aa2\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6472593276\" title=\"Palette Genius for macOS\"\u003e\u003cimg align=\"center\" alt=\"Palette Genius\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/27340413-d355-45b2-8f6f-6ac37682d957\"\u003e\u003c/a\u003e\n  \u003ca target=\"_blank\" href=\"https://apps.apple.com/app/6470879005\" title=\"Symbol Scribe for macOS\"\u003e\u003cimg align=\"center\" alt=\"Symbol Scribe\" height=\"52\" width=\"52\" src=\"https://github.com/jaywcjlove/jaywcjlove/assets/1680273/c7249f05-fa70-4def-a1e9-571d5f171fc9\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003chr\u003e\n\nFileType\n===\n\nThis tool detects a file’s MIME type using magic bytes and can retrieve the file extension based on the MIME type.  \nIt can identify the MIME type of `Data`, based on [Swime](https://github.com/sendyhalim/Swime) and ported from [file-type](https://www.npmjs.com/package/file-type).\n\nThe [`Extensions`](./Sources/FileType/Supported.swift), [`mimeTypes`](./Sources/FileType/Supported.swift), and [`mimeTypesAll`](./Sources/FileType/Supported.swift) data in the dependency package are all generated by scripts based on [file-type](https://www.npmjs.com/package/file-type).  \n\nThe function for checking whether the bytes match the `MimeType` specification is generated from a [`mapping.js`](./scripts/mapping.js) mapping file created using data from the `file-type` package.  \nSince the data may not always be accurate, it can be corrected by modifying the [`mapping.js`](./scripts/mapping.js) file.\n\n## Installation\n\n### Swift Package Manager\n\nAdd CodeMirror to your project using Xcode:\n\n1. In Xcode, go to `File` → `Add Package Dependencies...`\n2. Enter the repository URL: `https://github.com/jaywcjlove/FileType.git`\n3. Click `Add Package`\n\nOr add it to your `Package.swift` file:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/jaywcjlove/FileType.git\", from: \"1.0.0\")\n]\n```\n\n## Usage\n\nInspect mime type\n\n```swift\nimport FileType\n\nlet path = \"/path/to/some-file.jpg\"\nlet url = URL(fileURLWithPath: path, isDirectory: false)\nlet data = try! Data(contentsOf: url)\nlet mimeType = FileType.mimeType(data: data)\n\nmimeType?.type == .jpg // true\nmimeType! // MimeType(mime: \"image/jpeg\", ext: \"jpg\", type: .jpg)\n```\n\nGet the file extension from a MIME type\n\n```swift\nlet avroMimeType = MimeType.mimeTypesAll.first { $0.mime == \"application/avro\" }\nif let avroMimeType = avroMimeType {\n    avroMimeType.mime   // \"application/avro\"\n    avroMimeType.type   // .avro\n    avroMimeType.type.rawValue // \"avro\"\n}\n```\n\n```swift\nlet mimeTypes = MimeType.mimeTypes.first(where: { $0.key == \"application/mp4\" })\nif let mimeTypes = mimeTypes {\n    mimeTypes.compressible\n    mimeTypes.extensions // [\"mp4\",\"mpg4\",\"mp4s\",\"m4p\"]\n}\n```\n\n## Acknowledgments\n\nThanks to these projects:\n\n- https://github.com/sendyhalim/Swime\n- https://github.com/sindresorhus/file-type\n- https://github.com/jshttp/mime-db\n\n## License\n\nLicensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaywcjlove%2Ffiletype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaywcjlove%2Ffiletype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaywcjlove%2Ffiletype/lists"}