On this page:
octet-stream?
application/  octet-stream
octet-stream
octet-stream->bitstring
octet-stream-bytes
octet-stream-padding
media->octet-stream
octet-stream->media
7.4

10 Octet Streams

 (require rebellion/media/application/octet-stream)
  package: rebellion

An octet stream is an immutable byte string whose last byte may include extra bits of padding, making octet streams semantically similar to bitstrings. Octet streams are media, and their media type is application/octet-stream.

procedure

(octet-stream? v)  boolean?

  v : any/c
A predicate for octet streams.

procedure

(application/octet-stream [#:padding padding])  media-type?

  padding : (integer-in 0 7) = 0
Constructs the media type of octet streams padded with padding bits.

Examples:
> (application/octet-stream)

(media-type "application/octet-stream")

> (application/octet-stream #:padding 6)

(media-type "application/octet-stream; padding=6")

procedure

(octet-stream bstr [#:padding padding])  octet-stream?

  bstr : immutable-bytes?
  padding : (integer-in 0 7) = 0
Constructs an octet stream from bstr. If padding is nonzero, that many bits are ignored from the last byte of bstr when the octet stream is converted to a bitstring with octet-stream->bitstring.

Examples:
> (octet-stream #"Apple")

(octet-stream #"Apple" 0)

> (octet-stream #"Apple" #:padding 3)

(octet-stream #"Apple" 3)

procedure

(octet-stream->bitstring octets)  bitstring?

  octets : octet-stream?
Converts octets into a bitstring.

Examples:
> (octet-stream->bitstring (octet-stream #"Apple"))

(bitstring

 0

 1

 0

 0

 0

 0

 0

 1

 0

 1

 1

 1

 0

 0

 0

 0

 0

 1

 1

 1

 0

 0

 0

 0

 0

 1

 1

 0

 1

 1

 0

 0

 0

 1

 1

 0

 0

 1

 0

 1)

> (octet-stream->bitstring (octet-stream #"Apple" #:padding 3))

(bitstring

 0

 1

 0

 0

 0

 0

 0

 1

 0

 1

 1

 1

 0

 0

 0

 0

 0

 1

 1

 1

 0

 0

 0

 0

 0

 1

 1

 0

 1

 1

 0

 0

 0

 1

 1

 0

 0)

procedure

(octet-stream-bytes octets)  immutable-bytes?

  octets : octet-stream?
Returns the bytes contained in octets.

procedure

(octet-stream-padding octets)  (integer-in 0 7)

  octets : octet-stream?
Returns the number of padding bits in octets.

procedure

(media->octet-stream m)  octet-stream?

  m : media?
Constructs an octet stream containing the bytes of m. Octet streams are the most general media type, so all media can be converted to an octet stream regardless of type. However, the returned octet stream will only have nonzero padding if m has type application/octet-stream with the #:padding parameter set.

procedure

(octet-stream->media octets)  media?

  octets : octet-stream?
Converts octets into media of type application/octet-stream with the padding parameter set if octets has nonzero padding.

Examples:
> (octet-stream->media (octet-stream #"Apple"))

(media (media-type "application/octet-stream") #"Apple")

> (octet-stream->media (octet-stream #"Apple" #:padding 3))

(media (media-type "application/octet-stream; padding=3") #"Apple")