Encode

angerangel edited this page Jan 3, 2013 · 1 revision
Clone this wiki locally

USAGE

   ENCODE type data /options opts

DESCRIPTION

Encodes a datatype (e.g. image!) into a series of bytes.

ENCODE is a function value.

ARGUMENTS

  • type -- Media type (jpeg, png, etc.) (word!)
  • data -- The data to encode (image! binary! string!)

REFINEMENTS

  • /options
    • opts -- Special encoding options (block!)

#SOURCE

encode: make function! [  [
    {Encodes a datatype (e.g. image!) into a series of bytes.}
    type [word!] "Media type (jpeg, png, etc.)"
    data [image! binary! string!] "The data to encode"
    /options opts [block!] "Special encoding options"
    /local cod
][
    unless all [
        cod: select system/codecs type
        data: do-codec cod/entry 'encode data
    ] [
        cause-error 'access 'no-codec type
    ]
    data
] ]