function
Library: Base 64 (OMFFBASE64)
Import : omffbase64.xmd |
Returns: A scannable input source for streaming data. |
export external string source function reader from value string source input-data
Use base64.reader
to read its value string source
input-data argument, and
return the binary data converted from a Base 64 encoding to raw binary octets. That is, the provided data is in
Base 64, but the program sees binary data.
Any input data not recognized as part of a Base 64 encoding is ignored, so this library should not be used to validate Base 64 encoding.
The function read-attachment () below reads as much Base 64 as can be found in its string
source
argument, passes it through base64.reader
, thereby converting it from Base 64 to raw binary data,
and emits the raw data on its #current-output
.
import "omffbase64.xmd" prefixed by base64. define string source function read-attachment (value string source s) as output base64.reader from (s take [letter | digit | "+/=%10#%13#"]+)
Base 64 data can be padded with one or two =
characters when the original binary data is not a
multiple of three bytes. When base64.reader
is used to decode such a padded string
, the trailing
bytes are mapped to null bytes. If these trailing null bytes are undesired, they can be removed by using pattern
matching, as in
output (omffbase64.reader from #current-input) take any ++ lookahead ("%0#"* value-end)
To use base64.reader
, you must import OMFFBASE64 into your program using an
import declaration such as:
import "omffbase64.xmd" prefixed by base64.