Mimetypes
MIME content type registry & recognition package for Arturo
What does this package do?
This package provides an ample (2000+) entry database of MIME content types and their corresponding extensions and allows to easily look up the suitable MIME types by file extension (or file path). It also supports the reverse operation: look up possible extensions, based on a given MIME type.
Tip
For the data, the package has been based on the very useful list compiled by the mime-db project.
How do I use it?
Simply import it and use the included mimetype function:
import "mimetypes"!
mimetype "jpg" ; => ["image/jpeg"]
mimetype "somefile.jpg" ; => ["image/jpeg"]
mimetype "boom" ; => []
mimetype.best "photo.JPG" ; => "image/jpeg"
mimetype.best "file.xml" ; => "application/xml"
mimetype.best "boom" ; => null
mimetype.extensions "image/jpeg"
; => ["jpg","jpeg","jpe"]
mimetype.extensions.best "audio/mpeg"
; => "mp3"
Important
In case no suitable MIME type has been found for a given extension/path, or if the given MIME type isn't associated with any known extensions, thenmimetypewill return an empty block - ornull, if.bestis used!
Note
Results are always ordered by preference (most suitable first) - and that's what.bestpicks:
- for MIME types (by extension), using the same scoring as the mime-types package
- for extensions (by MIME type), using mime-db's own order - except for
audio/aac→aac,audio/mpeg→mp3andvideo/quicktime→mov
Function reference
mimetype
Description
get mimetype(s) from given extension/filepath
Usage
mimetype location :string
Attributes
| Option | Type(s) | Description |
|---|---|---|
| extensions | get possible file extensions for given mimetype instead | |
| best | get only the best match (or null, if none) |
Returns
- :block
- :string (when
.bestis used and a match has been found) - :null (when
.bestis used and no match has been found)
Updating the database
Both src/mimedb.art and src/extdb.art are generated from mime-db - to update them, bump mimedbVersion in tools/generate.art and run:
arturo tools/generate.art
License
MIT License
Copyright (c) 2026 Yanis Zafirópulos
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
| 1.0.0 | 31 October 2026 | 119346 / 10 files |
| 0.0.4 | 30 September 2024 | 57444 / 6 files |
| 0.0.3 | 29 April 2024 | 57029 / 5 files |
| 0.0.2 | 17 April 2024 | 56850 / 5 files |
| 0.0.1 | 17 April 2024 | 56846 / 5 files |
No dependencies.