All Projects → gabriel-vasile → Mimetype

gabriel-vasile / Mimetype

Licence: mit
A fast golang library for MIME type and file extension detection, based on magic numbers

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Mimetype

Filetype
Fast, dependency-free, small Go package to infer the binary file type based on the magic numbers signature
Stars: ✭ 1,278 (+182.74%)
Mutual labels:  mime, validation, extension, mime-types
ruby-magic
Simple interface to libmagic for Ruby Programming Language
Stars: ✭ 23 (-94.91%)
Mutual labels:  validation, mime, mime-types
mimesniff
MIME Sniffing Standard
Stars: ✭ 89 (-80.31%)
Mutual labels:  mime, mime-types, sniffing
Mime Db
Media Type Database
Stars: ✭ 612 (+35.4%)
Mutual labels:  mime, mime-types
Mime
Shared MIME-info database in D programming language
Stars: ✭ 7 (-98.45%)
Mutual labels:  mime, mime-types
Mime
The Hoa\Mime library.
Stars: ✭ 100 (-77.88%)
Mutual labels:  mime, mime-types
Swime
🗂 Swift MIME type checking based on magic bytes
Stars: ✭ 119 (-73.67%)
Mutual labels:  mime, mime-types
Mime Types
The ultimate javascript content-type utility.
Stars: ✭ 865 (+91.37%)
Mutual labels:  mime, mime-types
php-mime-detector
Detect a file's mime type using magic numbers.
Stars: ✭ 20 (-95.58%)
Mutual labels:  extension, mime
Fileio.jl
Main Package for IO, loading all different kind of files
Stars: ✭ 133 (-70.58%)
Mutual labels:  mime, mime-types
Mime
.NET wrapper for libmagic
Stars: ✭ 51 (-88.72%)
Mutual labels:  mime, mime-types
Filetype.py
Small, dependency-free, fast Python package to infer binary file types checking the magic numbers signature
Stars: ✭ 275 (-39.16%)
Mutual labels:  mime, extension
Indicative
Indicative is a simple yet powerful data validator for Node.js and browsers. It makes it so simple to write async validations on nested set of data.
Stars: ✭ 412 (-8.85%)
Mutual labels:  validation
Graphql Query Complexity
GraphQL query complexity analysis and validation for graphql-js
Stars: ✭ 424 (-6.19%)
Mutual labels:  validation
Fontisto
The iconic font and CSS toolkit. Fontisto gives you scalable vector icons that can instantly be customized: size, color, drop shadow and anything that can be done with the power of CSS.
Stars: ✭ 413 (-8.63%)
Mutual labels:  extension
Github Dark Theme
GitHub Dark Theme - Extension for Chrome, Firefox, and Microsoft Edge
Stars: ✭ 413 (-8.63%)
Mutual labels:  extension
Upmgitextension
This package extends the UI of Unity Package Manager (UPM) for the packages installed from git repository.
Stars: ✭ 438 (-3.1%)
Mutual labels:  extension
Githuber
Display Github Trending repositories on Chrome New Tab Extensions
Stars: ✭ 418 (-7.52%)
Mutual labels:  extension
Colander
A serialization/deserialization/validation library for strings, mappings and lists.
Stars: ✭ 408 (-9.73%)
Mutual labels:  validation
1click Webpage Screenshot
Entire page Screenshot extension for Google Chrome. I'm developing open source extension for Google Chrome. All extension are free for use. Let's make Chrome great again!
Stars: ✭ 406 (-10.18%)
Mutual labels:  extension

mimetype

A package for detecting MIME types and extensions based on magic numbers

No C bindings, zero dependencies and thread safe

Build Status Go Reference Go report card Go report card License

Features

  • fast and precise MIME type and file extension detection
  • long list of supported MIME types
  • common file formats are prioritized
  • small and simple API
  • handles MIME type aliases
  • thread safe
  • low memory usage, besides the file header

Install

go get github.com/gabriel-vasile/mimetype

Usage

mime := mimetype.Detect([]byte)
// OR
mime, err := mimetype.DetectReader(io.Reader)
// OR
mime, err := mimetype.DetectFile("/path/to/file")
fmt.Println(mime.String(), mime.Extension())

See the runnable Go Playground examples.

Structure

mimetype uses an hierarchical structure to keep the MIME type detection logic. This reduces the number of calls needed for detecting the file type. The reason behind this choice is that there are file formats used as containers for other file formats. For example, Microsoft Office files are just zip archives, containing specific metadata files. Once a file a file has been identified as a zip, there is no need to check if it is a text file, but it is worth checking if it is an Microsoft Office file.

To prevent loading entire files into memory, when detecting from a reader or from a file mimetype limits itself to reading only the header of the input.

structure

Performance

Thanks to the hierarchical structure, searching for common formats first, and limiting itself to file headers, mimetype matches the performance of stdlib http.DetectContentType while outperforming the alternative package.

Benchmarks were run on an Intel Xeon Gold 6136 24 core CPU @ 3.00GHz. Lower is better.

                            mimetype  http.DetectContentType      filetype
BenchmarkMatchTar-24       250 ns/op         400 ns/op           3778 ns/op
BenchmarkMatchZip-24       524 ns/op         351 ns/op           4884 ns/op
BenchmarkMatchJpeg-24      103 ns/op         228 ns/op            839 ns/op
BenchmarkMatchGif-24       139 ns/op         202 ns/op            751 ns/op
BenchmarkMatchPng-24       165 ns/op         221 ns/op           1176 ns/op

Contributing

See CONTRIBUTING.md.

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].