Codecs are standardized components dedicated to the encoding and decoding of dataset formats accessed through IO or from memory. Codecs are indirectly called by LOAD and SAVE functions.
encode <data> <type> /options <opts>
<data> : The data to encode (image! binary! string!)
<type> : Media type (jpeg, png, etc.) (word!)
<opts> : Special encoding options (block!)
Proposed implementation:
encode: function [
"Encodes Red data into a series of bytes"
data [image! binary! string!] "The data to encode"
type [word!] "Media type (jpeg, png, etc.)"
/options opts [block!] "Special encoding options"
][
unless codec: select system/codecs type [
cause-error 'access 'no-codec type
]
codec/encode data make codec/options any [opts []]
]
decode <data> <type> /options <opts>
<data> : The data to encode (image! binary! string!)
<type> : Media type (jpeg, png, etc.) (word!)
<opts> : Special encoding options (block!)
Proposed implementation:
decode: function [
"Decodes a series of bytes into the related datatype"
data [image! binary! string!] "The data to encode"
type [word!] "Media type (jpeg, png, etc.)"
/options opts [block!] "Special encoding options"
][
unless codec: select system/codecs type [
cause-error 'access 'no-codec type
]
codec/decode data make codec/options any [opts []]
]
system/standard/codec: object [
title: ; [string!] Codec's short description (80 chars max)
name: ; [word!] Codec's name
mime-type: ; [path! block!] Associated MIME type or list of types
suffixes: ; [file! block!] Associated file extension(s)
options: ; [object!] Default options
?? session: ; [object!] Session values
help: ; [block!]
encode: ; [function! routine!] Encoder function
decode: ; [function! routine!] Decoder function
]
encode: func [data [any-type!] opts [object!]]
decode: func [data [string! binary! file!] opts [object!]]