Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This tool checks a file’s MIME type using magic bytes and can retrieve the file extension from the MIME type.

License

NotificationsYou must be signed in to change notification settings

jaywcjlove/FileType

Repository files navigation

Usingmy app is also a way tosupport me:
KeyzerVidwall HubVidCropVidwallMousio HintMousioMusicerAudioerFileSentinelFocusCursorVideoerKeyClickerDayBarIconedMousioQuick RSSQuick RSSWeb ServeCopybook GeneratorDevTutor for SwiftUIRegexMateTime PassageIconize FolderTextsound SaverCreate Custom SymbolsDevHubResume RevisePalette GeniusSymbol Scribe

FileType

This tool detects a file’s MIME type using magic bytes and can retrieve the file extension based on the MIME type.
It can identify the MIME type ofData, based onSwime and ported fromfile-type.

TheExtensions,mimeTypes, andmimeTypesAll data in the dependency package are all generated by scripts based onfile-type.

The function for checking whether the bytes match theMimeType specification is generated from amapping.js mapping file created using data from thefile-type package.
Since the data may not always be accurate, it can be corrected by modifying themapping.js file.

Installation

Swift Package Manager

Add CodeMirror to your project using Xcode:

  1. In Xcode, go toFileAdd Package Dependencies...
  2. Enter the repository URL:https://github.com/jaywcjlove/FileType.git
  3. ClickAdd Package

Or add it to yourPackage.swift file:

dependencies:[.package(url:"https://github.com/jaywcjlove/FileType.git", from:"1.0.0")]

Usage

Inspect mime type

import FileTypeletpath="/path/to/some-file.jpg"leturl=URL(fileURLWithPath: path, isDirectory:false)letdata=try!Data(contentsOf: url)letmimeType=FileType.mimeType(data: data)mimeType?.type==.jpg // truemimeType! // MimeType(mime: "image/jpeg", ext: "jpg", type: .jpg)

Get the file extension from a MIME type

letavroMimeType=MimeType.mimeTypesAll.first{ $0.mime=="application/avro"}iflet avroMimeType= avroMimeType{    avroMimeType.mime   // "application/avro"    avroMimeType.type   // .avro    avroMimeType.type.rawValue // "avro"}
letmimeTypes=MimeType.mimeTypes.first(where:{ $0.key=="application/mp4"})iflet mimeTypes= mimeTypes{    mimeTypes.compressible    mimeTypes.extensions // ["mp4","mpg4","mp4s","m4p"]}

Acknowledgments

Thanks to these projects:

License

Licensed under the MIT License.

About

This tool checks a file’s MIME type using magic bytes and can retrieve the file extension from the MIME type.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp