{"id":21927013,"url":"https://github.com/rzane/file_type","last_synced_at":"2025-04-19T17:25:59.302Z","repository":{"id":56437219,"uuid":"308147829","full_name":"rzane/file_type","owner":"rzane","description":"Detect the MIME type of a file based on it's content.","archived":false,"fork":false,"pushed_at":"2024-05-28T18:30:56.000Z","size":57891,"stargazers_count":7,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T10:50:37.613Z","etag":null,"topics":["content-detection","elixir","file","image","mime"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/file_type","language":"Elixir","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/rzane.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":"2020-10-28T21:42:12.000Z","updated_at":"2024-06-15T18:21:50.000Z","dependencies_parsed_at":"2022-08-15T18:40:45.859Z","dependency_job_id":null,"html_url":"https://github.com/rzane/file_type","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Ffile_type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Ffile_type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Ffile_type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rzane%2Ffile_type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rzane","download_url":"https://codeload.github.com/rzane/file_type/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732389,"owners_count":21152849,"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":["content-detection","elixir","file","image","mime"],"created_at":"2024-11-28T22:13:01.857Z","updated_at":"2025-04-19T17:25:59.274Z","avatar_url":"https://github.com/rzane.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FileType\n\n[![github.com](https://img.shields.io/github/workflow/status/rzane/file_type/Build.svg)](https://github.com/rzane/file_type/actions?query=workflow%3ABuild)\n[![coveralls.io](https://img.shields.io/coveralls/github/rzane/file_type.svg)](https://coveralls.io/github/rzane/file_type)\n[![hex.pm](https://img.shields.io/hexpm/v/file_type.svg)](https://hex.pm/packages/file_type)\n[![hex.pm](https://img.shields.io/hexpm/dt/file_type.svg)](https://hex.pm/packages/file_type)\n[![hex.pm](https://img.shields.io/hexpm/l/file_type.svg)](https://hex.pm/packages/file_type)\n[![github.com](https://img.shields.io/github/last-commit/rzane/file_type.svg)](https://github.com/rzane/file_type/commits/master)\n\nThis package can be used to detect the MIME type and canonical extension by looking for [magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files). It works by reading a small amount of data from the file (~256 bytes) and binary pattern matching against it's contents.\n\n[API Documentation](https://hexdocs.pm/file_type/FileType.html)\n\n## Usage\n\nDetecting a file's type:\n\n```elixir\niex\u003e FileType.from_path(\"profile.png\")\n{:ok, {\"png\", \"image/png\"}}\n\niex\u003e FileType.from_path(\"contract.docx\")\n{:ok, {\"docx\", \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\"}}\n```\n\nDetect a file's type from an IO:\n\n```elixir\niex\u003e {:ok, file} = File.open(\"profile.png\", [:read, :binary])\n{:ok, file}\n\niex\u003e FileType.from_io(file)\n{:ok, {\"png\", \"image/png\"}}\n```\n\n## Installation\n\nThe package can be installed by adding `file_type` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:file_type, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Supported types\n\n#### Document\n\n- [`docx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Word Open XML Document\n- [`pptx`](https://en.wikipedia.org/wiki/Office_Open_XML) - PowerPoint Open XML Presentation\n- [`xlsx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Excel Open XML Spreadsheet\n- [`doc`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) - Microsoft Word Document\n- [`ppt`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) - PowerPoint Presentation\n- [`xls`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) - Excel Spreadsheet\n- [`pdf`](https://en.wikipedia.org/wiki/Portable_Document_Format) - Portable Document Format File\n- [`epub`](https://en.wikipedia.org/wiki/EPUB) - Open eBook File\n- [`mobi`](https://en.wikipedia.org/wiki/Mobipocket) - Mobipocket eBook\n- [`odt`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument Text Document\n- [`ods`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument Spreadsheet\n- [`odp`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument Presentation\n- [`rtf`](https://en.wikipedia.org/wiki/Rich_Text_Format) - Rich Text Format File\n\n#### Image\n\n- [`jpg`](https://en.wikipedia.org/wiki/JPEG) - JPEG Image\n- [`png`](https://en.wikipedia.org/wiki/Portable_Network_Graphics) - Portable Network Graphic\n- [`apng`](https://en.wikipedia.org/wiki/APNG) - Animated Portable Network Graphic\n- [`gif`](https://en.wikipedia.org/wiki/GIF) - Graphical Interchange Format File\n- [`webp`](https://en.wikipedia.org/wiki/WebP) - WebP Image\n- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format) - Free Lossless Image Format File\n- [`cr2`](https://fileinfo.com/extension/cr2) - Canon Raw Image File\n- [`cr3`](https://fileinfo.com/extension/cr3) - Canon Raw 3 Image File\n- [`orf`](https://en.wikipedia.org/wiki/ORF_format) - Olympus RAW File\n- [`arw`](https://en.wikipedia.org/wiki/Raw_image_format#ARW) - Sony Digital Camera Image\n- [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Digital Negative Image File\n- [`nef`](https://www.nikonusa.com/en/learn-and-explore/a/products-and-innovation/nikon-electronic-format-nef.html) - Nikon Electronic Format RAW Image\n- [`rw2`](https://en.wikipedia.org/wiki/Raw_image_format) - Panasonic RAW Image\n- [`raf`](https://en.wikipedia.org/wiki/Raw_image_format) - Fuji RAW Image File\n- [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format) - Tagged Image File\n- [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format) - Bitmap Image File\n- [`icns`](https://en.wikipedia.org/wiki/Apple_Icon_Image_format) - macOS Icon Resource File\n- [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR) - JPEG XR Image\n- [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format) - Adobe Photoshop Document\n- [`dmg`](https://en.wikipedia.org/wiki/Apple_Disk_Image) - Apple Disk Image\n- [`ico`](https://en.wikipedia.org/wiki/ICO_(file_format)) - Icon File\n- [`bpg`](https://bellard.org/bpg/) - BPG Image\n- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000 Core Image File\n- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000 Compound Image File Format\n- [`jpx`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000 Image File\n- [`heic`](https://nokiatech.github.io/heif/technical.html) - High Efficiency Image Format\n- [`cur`](https://en.wikipedia.org/wiki/ICO_(file_format)) - Windows Cursor\n- [`ktx`](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) - Khronos Texture\n- [`avif`](https://en.wikipedia.org/wiki/AV1#AV1_Image_File_Format_(AVIF)) - AV1 Image\n- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image\n\n#### Video\n\n- [`mp4`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 Video File\n- [`mkv`](https://en.wikipedia.org/wiki/Matroska) - Matroska Video File\n- [`webm`](https://en.wikipedia.org/wiki/WebM) - WebM Video File\n- [`mov`](https://en.wikipedia.org/wiki/QuickTime_File_Format) - Apple QuickTime Movie\n- [`avi`](https://en.wikipedia.org/wiki/Audio_Video_Interleave) - Audio Video Interleave File\n- [`mpg`](https://en.wikipedia.org/wiki/MPEG-1) - MPEG Video File\n- [`ogv`](https://en.wikipedia.org/wiki/Ogg) - Ogg Video File\n- [`ogm`](https://en.wikipedia.org/wiki/Ogg) - Ogg Media File\n- [`flv`](https://en.wikipedia.org/wiki/Flash_Video) - Flash Video File\n- [`mts`](https://en.wikipedia.org/wiki/.m2ts) - AVCHD Video File\n- [`mj2`](https://en.wikipedia.org/wiki/Motion_JPEG_2000) - Motion JPEG 2000 Video Clip\n- [`3gp`](https://en.wikipedia.org/wiki/3GP_and_3G2#3GP) - 3GPP Multimedia File\n- [`3g2`](https://en.wikipedia.org/wiki/3GP_and_3G2#3G2) - 3GPP2 Multimedia File\n- [`m4v`](https://en.wikipedia.org/wiki/M4V) - iTunes Video File\n- [`m4p`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - iTunes Music Store Audio File\n- [`f4v`](https://en.wikipedia.org/wiki/Flash_Video) - Flash MP4 Video File\n- [`f4p`](https://en.wikipedia.org/wiki/Flash_Video) - Adobe Flash Protected Media File\n\n#### Audio\n\n- [`mp1`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_I) - MPEG-1 Layer 1 Audio File\n- [`mp2`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_II) - MPEG Layer II Compressed Audio File\n- [`mp3`](https://en.wikipedia.org/wiki/MP3) - MP3 Audio File\n- [`aac`](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) - Advanced Audio Coding File\n- [`ogg`](https://en.wikipedia.org/wiki/Ogg) - Ogg Vorbis Audio File\n- [`oga`](https://en.wikipedia.org/wiki/Ogg) - Ogg Vorbis Audio File\n- [`spx`](https://en.wikipedia.org/wiki/Ogg) - Ogg Vorbis Speex File\n- [`opus`](https://en.wikipedia.org/wiki/Opus_(audio_format)) - Opus Audio File\n- [`flac`](https://en.wikipedia.org/wiki/FLAC) - Free Lossless Audio Codec File\n- [`wav`](https://en.wikipedia.org/wiki/WAV) - WAVE Audio File\n- [`mid`](https://en.wikipedia.org/wiki/MIDI) - MIDI File\n- [`qcp`](https://en.wikipedia.org/wiki/QCP) - PureVoice Audio File\n- [`amr`](https://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec) - Adaptive Multi-Rate Codec File\n- [`aif`](https://en.wikipedia.org/wiki/Audio_Interchange_File_Format) - Audio Interchange File Format\n- [`ape`](https://en.wikipedia.org/wiki/Monkey%27s_Audio) - Monkey's Audio Lossless Audio File\n- [`wv`](https://en.wikipedia.org/wiki/WavPack) - WavPack Audio File\n- [`mpc`](https://en.wikipedia.org/wiki/Musepack) - Musepack Compressed Audio File\n- [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Delusion Digital Sound File\n- [`voc`](https://wiki.multimedia.cx/index.php/Creative_Voice) - Creative Labs Audio File\n- [`ac3`](https://www.atsc.org/standard/a522012-digital-audio-compression-ac-3-e-ac-3-standard-12172012/) - Audio Codec 3 File\n- [`m4a`](https://en.wikipedia.org/wiki/M4A) - MPEG-4 Audio File\n- [`m4b`](https://en.wikipedia.org/wiki/M4B) - MPEG-4 Audiobook File\n- [`f4a`](https://en.wikipedia.org/wiki/Flash_Video) - Adobe Flash Protected Audio File\n- [`f4b`](https://en.wikipedia.org/wiki/Flash_Video) - Extension Not Found\n- [`it`](https://wiki.openmpt.org/Manual:_Module_formats#The_Impulse_Tracker_format_.28.it.29) - Impulse Tracker Module\n- [`s3m`](https://wiki.openmpt.org/Manual:_Module_formats#The_ScreamTracker_3_format_.28.s3m.29) - ScreamTracker 3 Module\n- [`xm`](https://wiki.openmpt.org/Manual:_Module_formats#The_FastTracker_2_format_.28.xm.29) - Fasttracker 2 Extended Module\n\n#### Font\n\n- [`ttf`](https://en.wikipedia.org/wiki/TrueType) - TrueType Font\n- [`otf`](https://en.wikipedia.org/wiki/OpenType) - OpenType Font\n- [`woff`](https://en.wikipedia.org/wiki/Web_Open_Font_Format) - Web Open Font Format File\n- [`woff2`](https://en.wikipedia.org/wiki/Web_Open_Font_Format) - Web Open Font Format 2.0 File\n- [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType) - Embedded OpenType Font\n\n#### Archive\n\n- [`zip`](https://en.wikipedia.org/wiki/Zip_(file_format)) - Zipped File\n- [`tar`](https://en.wikipedia.org/wiki/Tar_(computing)#File_format) - Consolidated Unix File Archive\n- [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format)) - WinRAR Compressed Archive\n- [`gz`](https://en.wikipedia.org/wiki/Gzip) - Gnu Zipped Archive\n- [`bz2`](https://en.wikipedia.org/wiki/Bzip2) - Bzip2 Compressed File\n- [`7z`](https://en.wikipedia.org/wiki/7z) - 7-Zip Compressed File\n- [`xz`](https://en.wikipedia.org/wiki/Xz) - XZ Compressed Archive\n- [`ar`](https://en.wikipedia.org/wiki/Ar_(Unix)) - Midtown Madness Data File\n- [`Z`](https://fileinfo.com/extension/z) - Unix Compressed File\n- [`lz`](https://en.wikipedia.org/wiki/Lzip) - Lzip Compressed File\n- [`cfb`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) - Compound Binary File\n- [`cab`](https://en.wikipedia.org/wiki/Cabinet_(file_format)) - Windows Cabinet File\n- [`lzh`](https://en.wikipedia.org/wiki/LHA_(file_format)) - LZH Compressed File\n\n#### Application\n\n- [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format) - Adobe InDesign Document\n- [`skp`](https://en.wikipedia.org/wiki/SketchUp) - SketchUp Document\n- [`blend`](https://wiki.blender.org/index.php/Dev:Source/Architecture/File_Format) - Blender 3D Data File\n- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - Calendar File\n\n#### Executable\n\n- [`exe`](https://en.wikipedia.org/wiki/.exe) - Windows Executable File\n- [`rpm`](https://fileinfo.com/extension/rpm) - Red Hat Package Manager File\n- [`xpi`](https://en.wikipedia.org/wiki/XPInstall) - Cross-platform Installer Package\n- [`msi`](https://en.wikipedia.org/wiki/Windows_Installer) - Windows Installer Package\n- [`deb`](https://en.wikipedia.org/wiki/Deb_(file_format)) - Debian Software Package\n\n#### Other\n\n- [`ogx`](https://en.wikipedia.org/wiki/Ogg) - Ogg Vorbis Multiplexed Media File\n- [`swf`](https://en.wikipedia.org/wiki/SWF) - Shockwave Flash Movie\n- [`sqlite`](https://www.sqlite.org/fileformat2.html) - SQLite Database File\n- [`nes`](https://fileinfo.com/extension/nes) - Nintendo (NES) ROM File\n- [`crx`](https://developer.chrome.com/extensions/crx) - Chrome Extension\n- [`mxf`](https://en.wikipedia.org/wiki/Material_Exchange_Format) - Material Exchange Format File\n- [`wasm`](https://en.wikipedia.org/wiki/WebAssembly) - WebAssembly Binary File\n- [`xml`](https://en.wikipedia.org/wiki/XML) - XML File\n- [`glb`](https://github.com/KhronosGroup/glTF) - STK Globe File\n- [`pcap`](https://wiki.wireshark.org/Development/LibpcapFileFormat) - Packet Capture Data\n- [`lnk`](https://en.wikipedia.org/wiki/Shortcut_%28computing%29#Microsoft_Windows) - Windows Shortcut\n- [`alias`](https://en.wikipedia.org/wiki/Alias_%28Mac_OS%29) - macOS Alias\n- [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Meta Information Encapsulation\n- [`shp`](https://en.wikipedia.org/wiki/Shapefile) - Shapes File\n- [`arrow`](https://arrow.apache.org) - Arrow Columnar Format\n- [`ps`](https://en.wikipedia.org/wiki/Postscript) - PostScript File\n- [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript File\n- [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - PGP Security Key\n- [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Stereolithography File\n\n## Contributing\n\n### Benchmark\n\n```elixir\n$ mix benchmark\n```\n\n### Adding New File Type\n\nMost files can be detected with a single binary pattern match. To contribute support for new file type:\n\n1. Find an example file. Please make sure you have the rights to use this file.\n2. Register the fixture in `test/file_type/integration_test.exs`.\n3. Write some code to detect the file's type in `lib/file_type/magic.ex`.\n4. Update the `README` to include a mention of your new file format.\n5. Send a pull request!\n\nPlease note that this library is _not_ intended to detect text-based file formats like CSV, JSON, etc.\n\n## Prior Art\n\n- [file/file](https://github.com/file/file) - The canonical file-type detection library.\n- [sindresorhus/file-type](https://github.com/sindresorhus/file-type) - This library is mostly just a port\n  of that library.\n- [minad/mimemagic](https://github.com/minad/mimemagic) - A popular Ruby library for doing the same thing.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzane%2Ffile_type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frzane%2Ffile_type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frzane%2Ffile_type/lists"}