Next: , Previous: Formatted Output, Up: Top


51 Encoding/Decoding Using Base64

To load support for encoding/decoding strings using base64:

     (use-modules (ice-9 base64))
The base64 encoding (rfc 2045) is basically a 3-byte to
4-byte transform:

GGGGGGGG NNNNNNNN UUUUUUUU <=> GGGGGG GGNNNN NNNNUU UUUUUU
GGGGGGRR RRRROOOO OOKKKKKK <=> GGGGGG RRRRRR OOOOOO KKKKKK

modulo line breaks and terminating delimiters.  It is widely used
in MIME and other protocols where the transmission medium may not
be guaranteed 8-bit clean.
— Scheme Procedure: base64-encode out-port input [line-break [crlf?]]

Write to out-port the result of base64-encoding input and return the number of bytes written. If out-port is #t, send to the current output port. If out-port is #f, return the result as a string, instead. input may be a string or a port.

Optional third arg line-break specifies the maximum number of columns to appear in the result before a line break. Actual number of columns is a rounded-down multiple of four, but not less than four. The result never ends with a line break. #f means omit line breaks entirely.

Optional fourth arg crlf? non-#f means use crlf for line breaks instead of simply lf.

— Scheme Procedure: base64-decode out-port input

Write to out-port the result of base64-decoding input and return the number of bytes written. If out-port is #t, send to the current output port. If out-port is #f, return the result as a string, instead. input may be a string or a port.