base64.writer

function

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

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


Purpose

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

writer has an optional first argument, heralded by 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 (CR+LF) sequence after the number of characters (of the Base 64 encoding) specified in the optional first argument. The Base 64 output always has a CR+LF at its end.

The optional first argument of writer can alternatively have a value of zero (0), in which case no CR+LF sequences are produced, and the output consists entirely of encoded data.

Usage Note

To use omffbase64, you must import it into your program using a statement like this:

  import "omffbase64.xmd" prefixed by base64.

(Please see the import topic for more on importing.)

Example


  ; Write a provided header and the associated data as an email
  ; attachment body, with the data converted to BASE64 encoding.
  ; The encoded data needs to be buffered because it is being
  ; incorporated in an output into which other data is being
  ; written.
  import "omffbase64.xmd" prefixed by base64.
  import "omiobuf.xmd" prefixed by io.
  define function write-attachment (value string header,
                                    value string data)
     as
     local io.buffer buf
     set base64.writer into io.writer of buf to data
     output header || "%16r{0D,0A}" || io.reader of buf

Related Topics
Other Library Functions