The trivial-mimes Reference Manual

This is the trivial-mimes Reference Manual, version 1.1.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Feb 26 18:08:08 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 trivial-mimes

Tiny library to detect mime types in files.

Maintainer

Yukari Hafner <>

Author

Yukari Hafner <>

Home Page

https://Shinmera.github.io/trivial-mimes/

Source Control

(GIT https://github.com/Shinmera/trivial-mimes.git)

Bug Tracker

https://github.com/Shinmera/trivial-mimes/issues

License

zlib

Version

1.1.0

Source

trivial-mimes.asd.

Child Component

mime-types.lisp (file).


3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 trivial-mimes/trivial-mimes.asd

Source

trivial-mimes.asd.

Parent Component

trivial-mimes (system).

ASDF Systems

trivial-mimes.


3.1.2 trivial-mimes/mime-types.lisp

Source

trivial-mimes.asd.

Parent Component

trivial-mimes (system).

Packages

trivial-mimes.

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 trivial-mimes

Source

mime-types.lisp.

Nicknames
  • mimes
  • org.tymoonnext.trivial-mimes
Use List

common-lisp.

Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Special variables

Special Variable: *mime-db*

An EQUALP hash-table with file-extensions as keys and the mime-types as values.

Package

trivial-mimes.

Source

mime-types.lisp.


5.1.2 Macros

Macro: mime-case (file &body cases)

A case-like macro that works with MIME type of FILE.

Otherwise clause is the last clause that starts with T or OTHERWISE,.

Example:
(mime-case #p"~/CHANGES.txt"
(("application/json" "application/*") "Something opaque...") ("text/plain" "That’s a plaintext file :D")
(t "I don’t know this type!"))

Package

trivial-mimes.

Source

mime-types.lisp.


5.1.3 Ordinary functions

Function: find-mime.types ()

Attempts to find a usable MIME.TYPES file. If none can be found, an error is signalled.

Package

trivial-mimes.

Source

mime-types.lisp.

Function: mime (pathname &optional default)

Attempts to detect the mime-type of the given pathname.
First uses MIME-LOOKUP, then MIME-PROBE and lastly returns the DEFAULT if both fail.

Package

trivial-mimes.

Source

mime-types.lisp.

Function: mime-add (mime &rest file-extensions)

Add MIME and FILE-EXTENSIONS associations to *MIME-DB* and *REVERSE-MIME-DB*. Makes the provided MIME and FILE-EXTENSIONS properly look-up-able with MIME, MIME-PROBE and other trivial-mimes functions.

Package

trivial-mimes.

Source

mime-types.lisp.

Function: mime-equal (m1 m2)

Checks whether M1 and M2 are matching.

In particular, checks the match of type and subtype (any of which can be asterisks), discarding any parameters there might be.

(mime-equal "text/*" "text/html")
T

(mime-equal "text/html" "text/html;charset=utf8")
T

(mime-equal "*/*" "application/octet-stream")
T

(mime-equal "text/*" "application/octet-stream")
NIL

Package

trivial-mimes.

Source

mime-types.lisp.

Function: mime-file-type (mime-type)

Returns a matching file-extension for the given mime-type. If the given mime-type cannot be found, NIL is returned.

Package

trivial-mimes.

Source

mime-types.lisp.

Function: mime-lookup (pathname)

Attempts to get the mime-type by file extension comparison. If none can be found, NIL is returned.

Package

trivial-mimes.

Source

mime-types.lisp.

Function: mime-probe (pathname)

Attempts to get the mime-type through a call to the FILE shell utility. If the file does not exist or the platform is not unix, NIL is returned.

Package

trivial-mimes.

Source

mime-types.lisp.


5.2 Internals


5.2.1 Special variables

Special Variable: *reverse-mime-db*

An EQUALP hash-table with mime-types as keys and the file-extensions as values.

Package

trivial-mimes.

Source

mime-types.lisp.


5.2.2 Ordinary functions

Function: %read-tokens (line)
Package

trivial-mimes.

Source

mime-types.lisp.

Function: build-mime-db (&optional file)

Populates the *MIME-DB* with data gathered from the file. The file should have the following structure:

MIME-TYPE FILE-EXTENSION*

Package

trivial-mimes.

Source

mime-types.lisp.

Function: valid-name-p (name)

According to RFC6838 type names MUST start with an alphanumeric character This also conveniently skips comments

Package

trivial-mimes.

Source

mime-types.lisp.

Function: whitespace-p (char)
Package

trivial-mimes.

Source

mime-types.lisp.


Appendix A Indexes


A.1 Concepts