8.3 Media
(require rebellion/media) | package: rebellion |
Media is binary data produced and consumed by programs according to a commonly understood format, called a media type. Media types aren’t defined by individual programs; rather, the Interned Assigned Numbers Authority (IANA) maintains a centralized global registry of all known media types. This process is intended to ensure different programs have the same interpretation of shared data, but know that even the most rigorously specified media type cannot guarantee consistency across all implementations.
The rebellion/media module does not provide any parsers or serialization implementations for individual media types. Instead, type-specific subcollections of rebellion/media provide functionality related to that type. For example, processing of text/plain data would be implemented in the rebellion/media/text/plain module. At present, rebellion does not provide any such implementations. In the future rebellion hopes to provide support for commonly encountered media types such as text/plain, text/csv, application/json, and image/jpeg.
procedure
type : media-type? bytes : immutable-bytes?
procedure
(media-get-type med) → media-type?
med : media?
procedure
(media-bytes med) → immutable-bytes?
med : media?
8.3.1 Media Types
A media type is a named specification registered with the Internet Assigned Numbers Authority (IANA) that defines a format for binary data, or media. All registered media types and their associated specifications can be found in the IANA Media Types Registry.
A media type consists of a top-level type and a subtype, and is registered in one of several registration trees. Optionally, a media type may have a structured suffix and/or parameters. Media types are written in the format:
top-level "/" [tree "."] subtype ["+" suffix] *[";" parameter]
For example, text/csv; charset=utf-8; header=present is the standards-tree media type for UTF-8 encoded CSV files that include an initial row of column headers. The allowed parameter names and values depend on the type and are specified in each type’s registration.
procedure
(media-type? v) → boolean?
v : any/c
procedure
(media-type top-level subtype [ #:tree tree #:suffix suffix #:parameters params]) → media-type? top-level : interned-symbol? subtype : interned-symbol? tree : (or/c #f interned-symbol?) = #f suffix : (or/c #f interned-symbol?) = #f params : record? = empty-record
procedure
(media-type-top-level type) → interned-symbol?
type : media-type?
procedure
(media-type-subtype type) → interned-symbol?
type : media-type?
procedure
(media-type-tree type) → (or/c interned-symbol? #f)
type : media-type?
procedure
(media-type-suffix type) → (or/c interned-symbol? #f)
type : media-type?
procedure
(media-type-params type) → record?
type : media-type?
procedure
(media-type->string type) → immutable-string?
type : media-type?