Internet Media Types
(require media-type) | package: media-type |
This package provides types and predicates for testing internet media types.
A media type (formerly known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. Their purpose is somewhat similar to file extensions in that they identify the intended data format. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication of these classifications.
mime-type := type "/" sub-type ["+" suffix] [";" parameter]*
sub-type := [tree "."] subtype
parameter := param-name "=" param-value
type := restricted-name
tree := restricted-name
subtype := restricted-name + "."
param-name := restricted-name + ":" "+" "."
struct
(struct media-type (type subtype suffix parameters))
type : media-type-type-string? subtype : (listof media-type-subtype-facet-string?) suffix : (or/c media-type-subtype-suffix-string? #f)
parameters :
(hash/c media-type-parameter-name-string? media-type-parameter-value-string?)
constructor
(string->media-type str) → media-type?
str : string?
> (let ((mt (string->media-type "application/vnd.3gpp.crs+xml"))) (displayln mt) (displayln (media-type-type mt)) (displayln (media-type-subtype mt)) (displayln (media-type-suffix mt)) (displayln (media-type-parameters mt)))
#(struct:media-type application (vnd 3gpp crs) xml #hash())
application
(vnd 3gpp crs)
xml
#hash()
procedure
(media-type-subtype-tree mt) → media-type-subtype-tree-string?
mt : media-type?
> (let ((mt (string->media-type "application/vnd.3gpp.crs+xml"))) (displayln (media-type-subtype mt)) (displayln (media-type-subtype-tree mt)))
(vnd 3gpp crs)
vnd
procedure
→ (listof media-type-subtype-facet-string?) mt : media-type?
> (let ((mt (string->media-type "application/vnd.3gpp.crs+xml"))) (displayln (media-type-subtype mt)) (displayln (media-type-subtype-facets mt)))
(vnd 3gpp crs)
(3gpp crs)
predicate
(media-type-vendor-tree? mt) → boolean?
mt : media-type?
> (let ((mt (string->media-type "application/vnd.3gpp.crs+xml"))) (displayln (media-type-vendor-tree? mt))) #t
predicate
mt : media-type?
> (let ((mt (string->media-type "application/prs.implied-object+json"))) (displayln (media-type-personal-tree? mt))) #t
predicate
(media-type-private-tree? mt) → boolean?
mt : media-type?
predicate
mt : media-type?
> (let ((mt (string->media-type "multipart/x-mixed-replace"))) (displayln (media-type-experimental-tree? mt))) #t
predicate
(media-type-has-facets? mt) → boolean?
mt : media-type?
> (let ((mt (string->media-type "application/prs.implied-object+json"))) (displayln (media-type-has-facets? mt))) #t
predicate
(media-type-has-suffix? mt) → boolean?
mt : media-type?
> (let ((mt (string->media-type "application/prs.implied-object+json"))) (displayln (media-type-has-suffix? mt))) #t
predicate
mt : media-type?
> (let ((mt (string->media-type "text/plain;charset=UTF-8"))) (displayln (media-type-has-parameters? mt))) #t
procedure
(media-type->string mt) → string?
mt : media-type?
> (displayln (media-type->string (string->media-type "application/prs.implied-object+json"))) application/prs.implied-object+json