All Projects → onevcat → MimeType

onevcat / MimeType

Licence: MIT License
Get MIME type string from the extension of a file name

Programming Languages

swift
15916 projects

MimeType

Get mime type from a file path or url extension. Like "text/html" for "/var/www/public/index.html" or "image/png" for "/home/user/cat.png".

Installation

Add the url of this repo to your Package.swift:

import PackageDescription

let package = Package(
    name: "YourAwesomeSoftware",
    dependencies: [
        .Package(url: "https://github.com/onevcat/MimeType.git", 
                 majorVersion: 1)
    ]
)

Then run swift build whenever you get prepared.

You could know more information on how to use Swift Package Manager in Apple's official page.

Usage

let path = "/var/www/public/index.html"
let mime = MimeType(path: path).value
// "text/html"

let url = URL(fileURLWithPath: "/home/user/cat.png")
let anotherMime = MimeType(url: url).value
// "image/png"

License

MIT. See the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].