Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sendyhalim/Swime
🗂 Swift MIME type checking based on magic bytes
https://github.com/sendyhalim/Swime
mime mime-parser mime-types mimetype swift
Last synced: about 1 month ago
JSON representation
🗂 Swift MIME type checking based on magic bytes
- Host: GitHub
- URL: https://github.com/sendyhalim/Swime
- Owner: sendyhalim
- License: mit
- Archived: true
- Created: 2017-03-22T13:38:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-27T17:56:13.000Z (almost 3 years ago)
- Last Synced: 2024-10-07T16:46:43.975Z (2 months ago)
- Topics: mime, mime-parser, mime-types, mimetype, swift
- Language: Swift
- Homepage:
- Size: 16.8 MB
- Stars: 180
- Watchers: 3
- Forks: 38
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-made-by-indonesian - Swime - `Swift MIME type checking based on magic bytes` *by [Sendy Halim](https://github.com/sendyhalim)* (S)
- made-in-indonesia - Swime - `Swift MIME type checking based on magic bytes` *by [Sendy Halim](https://github.com/sendyhalim)* (S)
README
# 🗂 Swime
Swift check MIME type based on magic bytes. Swime detects MIME type of a `Data`, ported from [sindresorhus/file-type](https://github.com/sindresorhus/file-type)[![Build Status](https://travis-ci.org/sendyhalim/Swime.svg?branch=master)](https://travis-ci.org/sendyhalim/Swime)
## Maintainers wanted
This project is not under active development, please go to [maintainers ticket](https://github.com/sendyhalim/Swime/issues/24) if you're interested.[![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg)](https://github.com/pickhardt/maintainers-wanted)
## Installation
### Swift Package Manager
```swift
import PackageDescriptionlet package = Package(
name: "MyApp",
dependencies: [
.Package(url: "https://github.com/sendyhalim/Swime", majorVersion: 3)
]
)
```## Usage
Inspect mime type
```swift
import Swimelet 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
```swift
import Swimelet bytes: [UInt8] = [255, 216, 255]
let mimeType = Swime.mimeType(bytes: bytes)mimeType! // MimeType(mime: "image/jpeg", ext: "jpg", type: .jpg)
```## MimeTypeExtension
Here are the list of available `MimeTypeExtension`.```swift
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
}
```## Testing
```
make test
```