Module base64

Search:
Group by:

This module implements a base64 encoder and decoder.

Encoding data

In order to encode some text simply call the encode procedure:

import base64
let encoded = encode("Hello World")
echo(encoded) # SGVsbG8gV29ybGQ=

Apart from strings you can also encode lists of integers or characters:

import base64
let encodedInts = encode([1,2,3])
echo(encodedInts) # AQID
let encodedChars = encode(['h','e','y'])
echo(encodedChars) # aGV5

The encode procedure takes an openarray so both arrays and sequences can be passed as parameters.

Decoding data

To decode a base64 encoded data string simply call the decode procedure:

import base64
echo(decode("SGVsbG8gV29ybGQ=")) # Hello World

Procs

proc encode[T: SomeInteger | char](s: openArray[T]; lineLen = 75; newLine = "\x0D\x0A"): string

encodes s into base64 representation. After lineLen characters, a newline is added.

This procedure encodes an openarray (array or sequence) of either integers or characters.

  Source Edit
proc encode(s: string; lineLen = 75; newLine = "\x0D\x0A"): string {.
raises: [], tags: []
.}

encodes s into base64 representation. After lineLen characters, a newline is added.

This procedure encodes a string.

  Source Edit
proc decode(s: string): string {.
raises: [], tags: []
.}
decodes a string in base64 representation back into its original form. Whitespace is skipped.   Source Edit