base64.writer

function

Library: Base 64 (OMFFBASE64)
Import : omffbase64.xmd

Returns: a writable output target for streaming data


Declaration
export external string sink function 
   writer width value integer     line-width optional initial { 76 }
           into value string sink output-data


Purpose

Use base64.writer to accept raw binary data and write that data to its value string sink output-data argument, converted from binary data to a Base 64 encoding. That is, the program writes binary data, but the provided output receives Base 64.

base64.writer has an optional first argument, line-width, that is the line width of the Base 64 output. The default is 76, in keeping with the specification for Base 64 encoding. The Base 64 output has line breaks, represented by a carriage-return/line-feed (%13#%10#) sequence after the number of characters (of the Base 64 encoding) specified by line-width. The Base 64 output always has a %13#%10# at its end.

The line-width argument of base64.writer can alternatively have a value of 0 (zero), in which case no %13#%10# sequences are produced, and the output consists entirely of encoded data.

Example

The function write-attachment () below takes raw binary data on its #current-input, as well as a provided header, and writes it as a an email attached body to the provided string sink argument.

  import "omffbase64.xmd" prefixed by base64.
  
  define string sink function 
     write-attachment (value string      header,
                       value string sink s)
  as
     using output as s
        output header || "%16r{0D,0A}"
        
     using output as base64.writer into s
        output #current-input

Usage Note

To use base64.writer, you must import OMFFBASE64 into your program using an import declaration such as:

  import "omffbase64.xmd" prefixed by base64.

Other Library Functions