The media-types Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The media-types Reference Manual

This is the media-types Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Thu Sep 15 05:37:35 2022 GMT+0.

Table of Contents


1 Introduction

MEDIA-TYPES is a library for querying and comparing media types.

Probably the most useful function is extension-media-type:

(extension-media-type "txt") => "text/plain"

An unknown extension, or no extension, has a media type of application/octet-stream:

(extension-media-type "my-fake-extension") => "application/octet-stream"
(extension-media-type nil) => "application/octet-stream"

(This is nonstandard, but reflects general practice.)

You can also use media-type-extension to query the extension (or extensions) for a media type:

(media-type-extension "application/javascript") => "js"

If a media type has multiple extensions, they are returned as multiple values:

(media-type-extension "image/jpeg") => "jpeg", "jpg", "jpe"

Extensions are not case sensitive:

(extension-media-type "TXT") => "text/plain"

You may pass the extension with or without a leading dot:

(extension-media-type ".txt") => "text/plain"

You can get the extension of a file name with file-name-extension:

(file-name-extension "file.txt") => "txt"

Or just get the media type of the file directly:

(file-name-media-type "file.txt") => "text/plain"
(file-name-media-type #p"file.txt") => "text/plain"

A file name without an extension has a media type of application/octet-stream:

(file-name-media-type "file") => "application/octet-stream"

However, if you want to test whether a file is of a specific media type, you should use file-name-media-typep.

(file-name-media-typep "file.xml" "application/xml") => t
(file-name-media-typep "file.svg" "application/xml") => t

file-name-media-typep uses media-subtypep, which has a sophisticated understanding of media types:

(media-subtypep "text/plain" "*/*") => t
(media-subtypep "text/plain" "text/*") => t

;; All media types are effectively subtypes of application/octet-stream.
(media-subtypep "text/plain" "application/octet-stream") => t

;; Structured syntax suffixes.
(media-subtypep "image/svg+xml" "application/xml") => t
(media-subtypep "application/vnd.my-format+json" "application/json") => t

;; Media type parameters.
(media-subtypep "application/atom+xml;type=entry" "application/xml") => t
(media-subtypep "application/atom+xml" "application/atom+xml;type=entry") => nil
(media-subtypep "application/atom+xml;charset=UTF8;type=entry"
                "application/atom+xml;type=entry")
=> t

;; The "q" pseudo-parameter is used in HTTP content negotiation.
(media-subtypep "application/json" "*/*;q=0.1") => t

MEDIA-TYPES uses the mime.types from the Apache sources.


2 Systems

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


Previous: , Up: Systems   [Contents][Index]

2.1 media-types

Query and compare media types.

Author

Paul M. Rodriguez <pmr@ruricolist.com>

License

MIT

Dependencies
  • alexandria (system).
  • serapeum (system).
  • cl-ppcre (system).
Source

media-types.asd.

Child Components

3 Files

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


Next: , Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.1 media-types/media-types.asd

Source

media-types.asd.

Parent Component

media-types (system).

ASDF Systems

media-types.


3.1.2 media-types/package.lisp

Source

media-types.asd.

Parent Component

media-types (system).

Packages

media-types.


3.1.3 media-types/media-types.lisp

Dependency

package.lisp (file).

Source

media-types.asd.

Parent Component

media-types (system).

Public Interface
Internals

3.1.4 media-types/file-extensions.lisp

Dependency

mime.types (file).

Source

media-types.asd.

Parent Component

media-types (system).

Public Interface
Internals

Previous: , Up: Files   [Contents][Index]

3.2 Static


Previous: , Up: Static   [Contents][Index]

3.2.1 media-types/mime.types

Dependency

media-types.lisp (file).

Source

media-types.asd.

Parent Component

media-types (system).


4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 media-types

Source

package.lisp.

Use List
  • alexandria.
  • common-lisp.
  • serapeum.
Public Interface
Internals

5 Definitions

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


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Public Interface


5.1.1 Compiler macros

Compiler Macro: file-name-media-typep (file type)
Package

media-types.

Source

file-extensions.lisp.

Compiler Macro: media-subtypep (subtype type)
Package

media-types.

Source

media-types.lisp.

Compiler Macro: media-type= (x y)
Package

media-types.

Source

media-types.lisp.


5.1.2 Ordinary functions

Function: extension-media-type (extension)
Package

media-types.

Source

file-extensions.lisp.

Function: file-name-extension (file)
Package

media-types.

Source

file-extensions.lisp.

Function: file-name-media-type (file)
Package

media-types.

Source

file-extensions.lisp.

Function: file-name-media-typep (file type)
Package

media-types.

Source

file-extensions.lisp.

Function: media-subtypep (subtype type)
Package

media-types.

Source

media-types.lisp.

Function: media-type (type subtype &rest params)
Package

media-types.

Source

media-types.lisp.

Function: media-type-extension (type)
Package

media-types.

Source

file-extensions.lisp.

Function: media-type-supers (type)
Package

media-types.

Source

media-types.lisp.

Function: media-type-values (type)
Package

media-types.

Source

media-types.lisp.

Function: media-type= (x y)
Package

media-types.

Source

media-types.lisp.

Function: parse-media-type (type &key allow-params)
Package

media-types.

Source

media-types.lisp.


5.1.3 Standalone methods

Method: print-object ((self media-type) stream)
Source

media-types.lisp.


5.1.4 Conditions

Condition: invalid-media-type
Package

media-types.

Source

media-types.lisp.

Direct superclasses

error.

Direct slots
Slot: type
Package

common-lisp.

Initargs

:type


Previous: , Up: Public Interface   [Contents][Index]

5.1.5 Structures

Structure: media-type
Package

media-types.

Source

media-types.lisp.

Direct superclasses

%read-only-struct.

Direct methods
Direct slots
Slot: type
Package

common-lisp.

Type

string

Initform

(alexandria:required-argument (quote type))

Readers

media-type-type.

Writers

This slot is read-only.

Slot: subtype
Type

string

Initform

(alexandria:required-argument (quote media-types::subtype))

Readers

media-type-subtype.

Writers

This slot is read-only.

Slot: params
Type

list

Readers

media-type-params.

Writers

This slot is read-only.


5.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.1 Constants

Constant: +storage-for-deflex-var-media-ranges+
Package

media-types.

Source

media-types.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.2 Special variables

Special Variable: *extension-media-types*
Package

media-types.

Source

file-extensions.lisp.

Special Variable: *media-type-extensions*
Package

media-types.

Source

file-extensions.lisp.


5.2.3 Symbol macros

Symbol Macro: application/cbor
Package

media-types.

Source

media-types.lisp.

Symbol Macro: application/fastinfoset
Package

media-types.

Source

media-types.lisp.

Symbol Macro: application/json
Package

media-types.

Source

media-types.lisp.

Symbol Macro: application/octet-stream
Package

media-types.

Source

media-types.lisp.

Symbol Macro: application/vnd.wap.wbxml
Package

media-types.

Source

media-types.lisp.

Symbol Macro: application/x-www-form-urlencoded
Package

media-types.

Source

media-types.lisp.

Symbol Macro: application/xml
Package

media-types.

Source

media-types.lisp.

Symbol Macro: application/zip
Package

media-types.

Source

media-types.lisp.

Symbol Macro: media-ranges
Package

media-types.

Source

media-types.lisp.

Symbol Macro: mime.types
Package

media-types.

Source

file-extensions.lisp.

Symbol Macro: multipart/form-data
Package

media-types.

Source

media-types.lisp.

Symbol Macro: suffix-types
Package

media-types.

Source

media-types.lisp.


5.2.4 Ordinary functions

Function: check-media-type-valid (type &key allow-params)
Package

media-types.

Source

media-types.lisp.

Function: comment? (line)
Package

media-types.

Source

file-extensions.lisp.

Function: dotted-extension? (x)
Package

media-types.

Source

file-extensions.lisp.

Function: ensure-q (type subtype q)
Package

media-types.

Source

media-types.lisp.

Function: extract-suffix (subtype)
Package

media-types.

Source

media-types.lisp.

Function: make-extension-to-type-table ()
Package

media-types.

Source

file-extensions.lisp.

Function: make-media-type (&key type subtype params)
Package

media-types.

Source

media-types.lisp.

Function: make-type-to-extension-table ()
Package

media-types.

Source

file-extensions.lisp.

Function: media-type-p (object)
Package

media-types.

Source

media-types.lisp.

Reader: media-type-params (instance)
Package

media-types.

Source

media-types.lisp.

Target Slot

params.

Reader: media-type-subtype (instance)
Package

media-types.

Source

media-types.lisp.

Target Slot

subtype.

Reader: media-type-type (instance)
Package

media-types.

Source

media-types.lisp.

Target Slot

type.

Function: media-type-valid (type &key allow-params)
Package

media-types.

Source

media-types.lisp.

Function: parse-media-type-string (type &key allow-params)
Package

media-types.

Source

media-types.lisp.

Function: render-media-type (self stream)
Package

media-types.

Source

media-types.lisp.

Function: render-media-type-params (alist stream)
Package

media-types.

Source

media-types.lisp.

Function: snarf-mime.types ()
Package

media-types.

Source

file-extensions.lisp.

Function: suffix-type (suffix)
Package

media-types.

Source

media-types.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.5 Standalone methods

Method: read-only-struct-slot-names append ((self media-type))
Package

serapeum.

Source

media-types.lisp.


5.2.6 Types

Type: bare-extension ()
Package

media-types.

Source

file-extensions.lisp.

Type: dotted-extension ()
Package

media-types.

Source

file-extensions.lisp.

Type: extension ()
Package

media-types.

Source

file-extensions.lisp.

Type: file-designator ()
Package

media-types.

Source

file-extensions.lisp.

Type: media-range ()
Package

media-types.

Source

media-types.lisp.

Type: media-type-designator ()
Package

media-types.

Source

media-types.lisp.

Type: no-extension ()
Package

media-types.

Source

file-extensions.lisp.

Type: type-extensions ()
Package

media-types.

Source

file-extensions.lisp.


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   C   D   E   F   M   P   R   S  
Index Entry  Section

C
check-media-type-valid: Private ordinary functions
comment?: Private ordinary functions
Compiler Macro, file-name-media-typep: Public compiler macros
Compiler Macro, media-subtypep: Public compiler macros
Compiler Macro, media-type=: Public compiler macros

D
dotted-extension?: Private ordinary functions

E
ensure-q: Private ordinary functions
extension-media-type: Public ordinary functions
extract-suffix: Private ordinary functions

F
file-name-extension: Public ordinary functions
file-name-media-type: Public ordinary functions
file-name-media-typep: Public compiler macros
file-name-media-typep: Public ordinary functions
Function, check-media-type-valid: Private ordinary functions
Function, comment?: Private ordinary functions
Function, dotted-extension?: Private ordinary functions
Function, ensure-q: Private ordinary functions
Function, extension-media-type: Public ordinary functions
Function, extract-suffix: Private ordinary functions
Function, file-name-extension: Public ordinary functions
Function, file-name-media-type: Public ordinary functions
Function, file-name-media-typep: Public ordinary functions
Function, make-extension-to-type-table: Private ordinary functions
Function, make-media-type: Private ordinary functions
Function, make-type-to-extension-table: Private ordinary functions
Function, media-subtypep: Public ordinary functions
Function, media-type: Public ordinary functions
Function, media-type-extension: Public ordinary functions
Function, media-type-p: Private ordinary functions
Function, media-type-params: Private ordinary functions
Function, media-type-subtype: Private ordinary functions
Function, media-type-supers: Public ordinary functions
Function, media-type-type: Private ordinary functions
Function, media-type-valid: Private ordinary functions
Function, media-type-values: Public ordinary functions
Function, media-type=: Public ordinary functions
Function, parse-media-type: Public ordinary functions
Function, parse-media-type-string: Private ordinary functions
Function, render-media-type: Private ordinary functions
Function, render-media-type-params: Private ordinary functions
Function, snarf-mime.types: Private ordinary functions
Function, suffix-type: Private ordinary functions

M
make-extension-to-type-table: Private ordinary functions
make-media-type: Private ordinary functions
make-type-to-extension-table: Private ordinary functions
media-subtypep: Public compiler macros
media-subtypep: Public ordinary functions
media-type: Public ordinary functions
media-type-extension: Public ordinary functions
media-type-p: Private ordinary functions
media-type-params: Private ordinary functions
media-type-subtype: Private ordinary functions
media-type-supers: Public ordinary functions
media-type-type: Private ordinary functions
media-type-valid: Private ordinary functions
media-type-values: Public ordinary functions
media-type=: Public compiler macros
media-type=: Public ordinary functions
Method, print-object: Public standalone methods
Method, read-only-struct-slot-names: Private standalone methods

P
parse-media-type: Public ordinary functions
parse-media-type-string: Private ordinary functions
print-object: Public standalone methods

R
read-only-struct-slot-names: Private standalone methods
render-media-type: Private ordinary functions
render-media-type-params: Private ordinary functions

S
snarf-mime.types: Private ordinary functions
suffix-type: Private ordinary functions

Jump to:   C   D   E   F   M   P   R   S  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *   +  
A   C   M   P   S   T  
Index Entry  Section

*
*extension-media-types*: Private special variables
*media-type-extensions*: Private special variables

+
+storage-for-deflex-var-media-ranges+: Private constants

A
application/cbor: Private symbol macros
application/fastinfoset: Private symbol macros
application/json: Private symbol macros
application/octet-stream: Private symbol macros
application/vnd.wap.wbxml: Private symbol macros
application/x-www-form-urlencoded: Private symbol macros
application/xml: Private symbol macros
application/zip: Private symbol macros

C
Constant, +storage-for-deflex-var-media-ranges+: Private constants

M
media-ranges: Private symbol macros
mime.types: Private symbol macros
multipart/form-data: Private symbol macros

P
params: Public structures

S
Slot, params: Public structures
Slot, subtype: Public structures
Slot, type: Public conditions
Slot, type: Public structures
Special Variable, *extension-media-types*: Private special variables
Special Variable, *media-type-extensions*: Private special variables
subtype: Public structures
suffix-types: Private symbol macros
Symbol Macro, application/cbor: Private symbol macros
Symbol Macro, application/fastinfoset: Private symbol macros
Symbol Macro, application/json: Private symbol macros
Symbol Macro, application/octet-stream: Private symbol macros
Symbol Macro, application/vnd.wap.wbxml: Private symbol macros
Symbol Macro, application/x-www-form-urlencoded: Private symbol macros
Symbol Macro, application/xml: Private symbol macros
Symbol Macro, application/zip: Private symbol macros
Symbol Macro, media-ranges: Private symbol macros
Symbol Macro, mime.types: Private symbol macros
Symbol Macro, multipart/form-data: Private symbol macros
Symbol Macro, suffix-types: Private symbol macros

T
type: Public conditions
type: Public structures

Jump to:   *   +  
A   C   M   P   S   T  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   B   C   D   E   F   I   M   N   P   S   T  
Index Entry  Section

B
bare-extension: Private types

C
Condition, invalid-media-type: Public conditions

D
dotted-extension: Private types

E
extension: Private types

F
File, file-extensions.lisp: The media-types/file-extensions․lisp file
File, media-types.asd: The media-types/media-types․asd file
File, media-types.lisp: The media-types/media-types․lisp file
File, mime.types: The media-types/mime․types file
File, package.lisp: The media-types/package․lisp file
file-designator: Private types
file-extensions.lisp: The media-types/file-extensions․lisp file

I
invalid-media-type: Public conditions

M
media-range: Private types
media-type: Public structures
media-type-designator: Private types
media-types: The media-types system
media-types: The media-types package
media-types.asd: The media-types/media-types․asd file
media-types.lisp: The media-types/media-types․lisp file
mime.types: The media-types/mime․types file

N
no-extension: Private types

P
Package, media-types: The media-types package
package.lisp: The media-types/package․lisp file

S
Structure, media-type: Public structures
System, media-types: The media-types system

T
Type, bare-extension: Private types
Type, dotted-extension: Private types
Type, extension: Private types
Type, file-designator: Private types
Type, media-range: Private types
Type, media-type-designator: Private types
Type, no-extension: Private types
Type, type-extensions: Private types
type-extensions: Private types

Jump to:   B   C   D   E   F   I   M   N   P   S   T