{"id":26569115,"url":"https://github.com/velocityzen/filetype","last_synced_at":"2025-03-22T20:19:38.607Z","repository":{"id":54474425,"uuid":"253146616","full_name":"velocityzen/FileType","owner":"velocityzen","description":"File type and mime detection by magic bytes","archived":false,"fork":false,"pushed_at":"2022-07-22T01:02:22.000Z","size":63579,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-04-10T01:47:11.402Z","etag":null,"topics":["detection","file","file-format","file-type","file-type-detection","file-types","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/velocityzen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-05T03:19:10.000Z","updated_at":"2023-02-23T10:51:21.000Z","dependencies_parsed_at":"2022-08-13T17:00:21.051Z","dependency_job_id":null,"html_url":"https://github.com/velocityzen/FileType","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velocityzen%2FFileType","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velocityzen%2FFileType/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velocityzen%2FFileType/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/velocityzen%2FFileType/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/velocityzen","download_url":"https://codeload.github.com/velocityzen/FileType/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245014888,"owners_count":20547327,"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","file","file-format","file-type","file-type-detection","file-types","swift"],"created_at":"2025-03-22T20:19:37.921Z","updated_at":"2025-03-22T20:19:38.586Z","avatar_url":"https://github.com/velocityzen.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FileType\n\nThe file type is detected by checking the magic number of the data.\n\nThis is swift port of [file-type](https://github.com/sindresorhus/file-type)\n\n## Installation\n\n### Swift Package Manager\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n  name: \"MyApp\",\n  dependencies: [\n    .package(url: \"https://github.com/velocityzen/FileType\", from: \"1.0.3\")\n  ]\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 fileType = FileType.getFor(data: data)\n\nfileType?.type == .jpg // true\nfileType! // FileType(type: .jpg, ext: \"jpg\", mime: \"image/jpeg\")\n\n```\n\n### .getFor(type: FileTypeExtension) -\u003e [FileType]\n\nreturns all file types and mime information\n\n### .getFor(data: Data) -\u003e FileType?\n\nreturns file type detected by checking the magic number\n\n### .getBytesCountFor(type: FileTypeExtension) -\u003e Int\n\nreturns bytes count needed to detect file type\n\n### .getBytesCountFor(types: [FileTypeExtension]) -\u003e Int\n\nreturns max bytes count needed to detect file types\n\n## Supported file types\n\n- [`3g2`](https://en.wikipedia.org/wiki/3GP_and_3G2#3G2) - Multimedia container format defined by the 3GPP2 for 3G CDMA2000 multimedia services\n- [`3gp`](https://en.wikipedia.org/wiki/3GP_and_3G2#3GP) - Multimedia container format defined by the Third Generation Partnership Project (3GPP) for 3G UMTS multimedia services\n- [`3mf`](https://en.wikipedia.org/wiki/3D_Manufacturing_Format) - 3D Manufacturing Format\n- [`7z`](https://en.wikipedia.org/wiki/7z)\n- [`aac`](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) - Advanced Audio Coding\n- [`ac3`](https://www.atsc.org/standard/a522012-digital-audio-compression-ac-3-e-ac-3-standard-12172012/) - ATSC A/52 Audio File\n- [`ai`](https://en.wikipedia.org/wiki/Adobe_Illustrator_Artwork) - Adobe Illustrator Artwork\n- [`aif`](https://en.wikipedia.org/wiki/Audio_Interchange_File_Format)\n- [`alias`](https://en.wikipedia.org/wiki/Alias_%28Mac_OS%29) - macOS Alias file\n- [`amr`](https://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec)\n- [`ape`](https://en.wikipedia.org/wiki/Monkey%27s_Audio) - Monkey's Audio\n- [`apng`](https://en.wikipedia.org/wiki/APNG) - Animated Portable Network Graphics\n- [`ar`](\u003chttps://en.wikipedia.org/wiki/Ar_(Unix)\u003e)\n- [`arrow`](https://arrow.apache.org) - Columnar format for tables of data\n- [`arw`](https://en.wikipedia.org/wiki/Raw_image_format#ARW) - Sony Alpha Raw image file\n- [`asar`](https://github.com/electron/asar) - Simple extensive tar-like archive format with indexing\n- [`asf`](https://en.wikipedia.org/wiki/Advanced_Systems_Format) - Advanced Systems Format\n- [`avi`](https://en.wikipedia.org/wiki/Audio_Video_Interleave)\n- [`avif`](\u003chttps://en.wikipedia.org/wiki/AV1#AV1_Image_File_Format_(AVIF)\u003e) - AV1 Image File Format\n- [`blend`](https://wiki.blender.org/index.php/Dev:Source/Architecture/File_Format)\n- [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format)\n- [`bpg`](https://bellard.org/bpg/)\n- [`bz2`](https://en.wikipedia.org/wiki/Bzip2)\n- [`cab`](\u003chttps://en.wikipedia.org/wiki/Cabinet_(file_format)\u003e)\n- [`cfb`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format)\n- [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help\n- [`cr2`](https://fileinfo.com/extension/cr2) - Canon Raw image file (v2)\n- [`cr3`](https://fileinfo.com/extension/cr3) - Canon Raw image file (v3)\n- [`crx`](https://developer.chrome.com/extensions/crx)\n- [`cur`](\u003chttps://en.wikipedia.org/wiki/ICO_(file_format)\u003e)\n- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File\n- [`deb`](\u003chttps://en.wikipedia.org/wiki/Deb_(file_format)\u003e)\n- [`dmg`](https://en.wikipedia.org/wiki/Apple_Disk_Image)\n- [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Adobe Digital Negative image file\n- [`docx`](https://en.wikipedia.org/wiki/Office_Open_XML)\n- [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)\n- [`elf`](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) - Unix Executable and Linkable Format\n- [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType)\n- [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript\n- [`epub`](https://en.wikipedia.org/wiki/EPUB)\n- [`exe`](https://en.wikipedia.org/wiki/.exe)\n- [`f4a`](https://en.wikipedia.org/wiki/Flash_Video) - Audio-only ISO base media file format used by Adobe Flash Player\n- [`f4b`](https://en.wikipedia.org/wiki/Flash_Video) - Audiobook and podcast ISO base media file format used by Adobe Flash Player\n- [`f4p`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format protected by Adobe Access DRM used by Adobe Flash Player\n- [`f4v`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format used by Adobe Flash Player\n- [`flac`](https://en.wikipedia.org/wiki/FLAC)\n- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format)\n- [`flv`](https://en.wikipedia.org/wiki/Flash_Video)\n- [`gif`](https://en.wikipedia.org/wiki/GIF)\n- [`glb`](https://github.com/KhronosGroup/glTF) - GL Transmission Format\n- [`gz`](https://en.wikipedia.org/wiki/Gzip)\n- [`heic`](https://nokiatech.github.io/heif/technical.html)\n- [`icns`](https://en.wikipedia.org/wiki/Apple_Icon_Image_format)\n- [`ico`](\u003chttps://en.wikipedia.org/wiki/ICO_(file_format)\u003e)\n- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar\n- [`indd`](https://en.wikipedia.org/wiki/Adobe_InDesign#File_format)\n- [`it`](https://wiki.openmpt.org/Manual:_Module_formats#The_Impulse_Tracker_format_.28.it.29) - Audio module format: Impulse Tracker\n- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000\n- [`jpg`](https://en.wikipedia.org/wiki/JPEG)\n- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000\n- [`jpx`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000\n- [`jxl`](https://en.wikipedia.org/wiki/JPEG_XL) - JPEG XL image format\n- [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR)\n- [`ktx`](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/)\n- [`lnk`](https://en.wikipedia.org/wiki/Shortcut_%28computing%29#Microsoft_Windows) - Microsoft Windows file shortcut\n- [`lz`](https://en.wikipedia.org/wiki/Lzip)\n- [`lzh`](\u003chttps://en.wikipedia.org/wiki/LHA_(file_format)\u003e) - LZH archive\n- [`m4a`](https://en.wikipedia.org/wiki/M4A) - Audio-only MPEG-4 files\n- [`m4b`](https://en.wikipedia.org/wiki/M4B) - Audiobook and podcast MPEG-4 files, which also contain metadata including chapter markers, images, and hyperlinks\n- [`m4p`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions) - MPEG-4 files with audio streams encrypted by FairPlay Digital Rights Management as were sold through the iTunes Store\n- [`m4v`](https://en.wikipedia.org/wiki/M4V) - MPEG-4 Visual bitstreams\n- [`mid`](https://en.wikipedia.org/wiki/MIDI)\n- [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Dedicated meta information format which supports storage of binary as well as textual meta information\n- [`mj2`](https://en.wikipedia.org/wiki/Motion_JPEG_2000) - Motion JPEG 2000\n- [`mkv`](https://en.wikipedia.org/wiki/Matroska)\n- [`mobi`](https://en.wikipedia.org/wiki/Mobipocket) - Mobipocket\n- [`mov`](https://en.wikipedia.org/wiki/QuickTime_File_Format)\n- [`mp1`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_I) - MPEG-1 Audio Layer I\n- [`mp2`](https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_II)\n- [`mp3`](https://en.wikipedia.org/wiki/MP3)\n- [`mp4`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions)\n- [`mpc`](https://en.wikipedia.org/wiki/Musepack) - Musepack (SV7 \u0026 SV8)\n- [`mpg`](https://en.wikipedia.org/wiki/MPEG-1)\n- [`mts`](https://en.wikipedia.org/wiki/.m2ts) - MPEG-2 Transport Stream, both raw and Blu-ray Disc Audio-Video (BDAV) versions\n- [`mxf`](https://en.wikipedia.org/wiki/Material_Exchange_Format)\n- [`nef`](https://www.nikonusa.com/en/learn-and-explore/a/products-and-innovation/nikon-electronic-format-nef.html) - Nikon Electronic Format image file\n- [`nes`](https://fileinfo.com/extension/nes)\n- [`odp`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for presentations\n- [`ods`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for spreadsheets\n- [`odt`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for word processing\n- [`oga`](https://en.wikipedia.org/wiki/Ogg)\n- [`ogg`](https://en.wikipedia.org/wiki/Ogg)\n- [`ogm`](https://en.wikipedia.org/wiki/Ogg)\n- [`ogv`](https://en.wikipedia.org/wiki/Ogg)\n- [`ogx`](https://en.wikipedia.org/wiki/Ogg)\n- [`opus`](\u003chttps://en.wikipedia.org/wiki/Opus_(audio_format)\u003e)\n- [`orf`](https://en.wikipedia.org/wiki/ORF_format) - Olympus Raw image file\n- [`otf`](https://en.wikipedia.org/wiki/OpenType)\n- [`pcap`](https://wiki.wireshark.org/Development/LibpcapFileFormat) - Libpcap File Format\n- [`pdf`](https://en.wikipedia.org/wiki/Portable_Document_Format)\n- [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - Pretty Good Privacy\n- [`png`](https://en.wikipedia.org/wiki/Portable_Network_Graphics)\n- [`pptx`](https://en.wikipedia.org/wiki/Office_Open_XML)\n- [`ps`](https://en.wikipedia.org/wiki/Postscript)\n- [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format)\n- [`qcp`](https://en.wikipedia.org/wiki/QCP)\n- [`raf`](https://en.wikipedia.org/wiki/Raw_image_format) - Fujifilm RAW image file\n- [`rar`](\u003chttps://en.wikipedia.org/wiki/RAR_(file_format)\u003e)\n- [`rpm`](https://fileinfo.com/extension/rpm)\n- [`rtf`](https://en.wikipedia.org/wiki/Rich_Text_Format)\n- [`rw2`](https://en.wikipedia.org/wiki/Raw_image_format) - Panasonic RAW image file\n- [`s3m`](https://wiki.openmpt.org/Manual:_Module_formats#The_ScreamTracker_3_format_.28.s3m.29) - Audio module format: ScreamTracker 3\n- [`shp`](https://en.wikipedia.org/wiki/Shapefile) - Geospatial vector data format\n- [`skp`](https://en.wikipedia.org/wiki/SketchUp) - SketchUp\n- [`spx`](https://en.wikipedia.org/wiki/Ogg)\n- [`sqlite`](https://www.sqlite.org/fileformat2.html)\n- [`stl`](\u003chttps://en.wikipedia.org/wiki/STL_(file_format)\u003e) - Standard Tesselated Geometry File Format (ASCII only)\n- [`swf`](https://en.wikipedia.org/wiki/SWF)\n- [`tar`](\u003chttps://en.wikipedia.org/wiki/Tar_(computing)#File_format\u003e)\n- [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format)\n- [`ttf`](https://en.wikipedia.org/wiki/TrueType)\n- [`vcf`](https://en.wikipedia.org/wiki/VCard) - vCard\n- [`voc`](https://wiki.multimedia.cx/index.php/Creative_Voice) - Creative Voice File\n- [`wasm`](https://en.wikipedia.org/wiki/WebAssembly)\n- [`wav`](https://en.wikipedia.org/wiki/WAV)\n- [`webm`](https://en.wikipedia.org/wiki/WebM)\n- [`webp`](https://en.wikipedia.org/wiki/WebP)\n- [`woff2`](https://en.wikipedia.org/wiki/Web_Open_Font_Format)\n- [`woff`](https://en.wikipedia.org/wiki/Web_Open_Font_Format)\n- [`wv`](https://en.wikipedia.org/wiki/WavPack) - WavPack\n- [`xcf`](\u003chttps://en.wikipedia.org/wiki/XCF_(file_format)\u003e) - eXperimental Computing Facility\n- [`xlsx`](https://en.wikipedia.org/wiki/Office_Open_XML)\n- [`xm`](https://wiki.openmpt.org/Manual:_Module_formats#The_FastTracker_2_format_.28.xm.29) - Audio module format: FastTracker 2\n- [`xml`](https://en.wikipedia.org/wiki/XML)\n- [`xpi`](https://en.wikipedia.org/wiki/XPInstall)\n- [`xz`](https://en.wikipedia.org/wiki/Xz)\n- [`Z`](https://fileinfo.com/extension/z)\n- [`zip`](\u003chttps://en.wikipedia.org/wiki/Zip_(file_format)\u003e)\n- [`zst`](https://en.wikipedia.org/wiki/Zstandard) - Archive file\n\n_Pull requests are welcome for additional commonly used file types._\n\n## Testing\n\n```\nswift test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvelocityzen%2Ffiletype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvelocityzen%2Ffiletype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvelocityzen%2Ffiletype/lists"}