Swiftpack.co - sendyhalim/Swime as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by sendyhalim.
sendyhalim/Swime 3.1.0
🗂 Swift MIME type checking based on magic bytes
⭐️ 146
🕓 8 weeks ago
iOS macOS
.package(url: "https://github.com/sendyhalim/Swime.git", from: "3.1.0")

🗂 Swime

Swift check MIME type based on magic bytes. Swime detects MIME type of a Data, ported from sindresorhus/file-type

Build Status

Maintainers wanted

This project is not under active development, please go to maintainers ticket if you're interested.

Maintainers Wanted


Swift Package Manager

import PackageDescription

let package = Package(
  name: "MyApp",
  dependencies: [
    .Package(url: "https://github.com/sendyhalim/Swime", majorVersion: 3)


Inspect mime type

import Swime

let path = "/path/to/some-file.jpg"
let url = URL(fileURLWithPath: path, isDirectory: false)
let data = try! Data(contentsOf: url)
let mimeType = Swime.mimeType(data: data)

mimeType?.type == .jpg // true
mimeType! // MimeType(mime: "image/jpeg", ext: "jpg", type: .jpg)

switch mimeType?.type {
  case .jpg?:
  case .png?:
  case .wmv?:

  case ...

Pass bytes to it

import Swime

let bytes: [UInt8] = [255, 216, 255]
let mimeType = Swime.mimeType(bytes: bytes)

mimeType! // MimeType(mime: "image/jpeg", ext: "jpg", type: .jpg)


Here are the list of available MimeTypeExtension.

public enum MimeTypeExtension {
  case amr
  case ar
  case avi
  case bmp
  case bz2
  case cab
  case cr2
  case crx
  case deb
  case dmg
  case eot
  case epub
  case exe
  case flac
  case flif
  case flv
  case gif
  case gz
  case ico
  case jpg
  case jxr
  case lz
  case m4a
  case m4v
  case mid
  case mkv
  case mov
  case mp3
  case mp4
  case mpg
  case msi
  case mxf
  case nes
  case ogg
  case opus
  case otf
  case pdf
  case png
  case ps
  case psd
  case rar
  case rpm
  case rtf
  case sevenZ // 7z, Swift does not let us define enum that starts with a digit
  case sqlite
  case swf
  case tar
  case tif
  case ttf
  case wav
  case webm
  case webp
  case wmv
  case woff
  case woff2
  case xpi
  case xz
  case z
  case zip
  case heic


make test


Stars: 146
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics