On this page:
media?
media
media-get-type
media-bytes
8.3.1 Media Types
media-type?
media-type
media-type-top-level
media-type-subtype
media-type-tree
media-type-suffix
media-type-params
media-type->string
7.7

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

(media? v)  boolean?

  v : any/c
A predicate for media.

procedure

(media type bytes)  media?

  type : media-type?
  bytes : immutable-bytes?
Constructs a piece of media of type type containing bytes. This constructor does not guarantee that bytes matches the format defined by type, merely that it is intended to match type. It is up to applications to decide how to handle ill-formed media.

procedure

(media-get-type med)  media-type?

  med : media?

procedure

(media-bytes med)  immutable-bytes?

  med : media?
Accessors for the media type and the binary content of med.

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
A predicate for media types.

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
Constructs a media type.

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?
Accessors for the various components of a media type.

procedure

(media-type->string type)  immutable-string?

  type : media-type?
Formats type as a string.