This module implements a base64 encoder and decoder.
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.
To decode a base64 encoded data string simply call the decode
procedure:
import base64 echo(decode("SGVsbG8gV29ybGQ=")) # Hello World
proc encode[T: SomeInteger | char](s: openArray[T]; lineLen = 75; newLine = "\c\n"): 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.
proc encode(s: string; lineLen = 75; newLine = "\c\n"): string {...}{.raises: [], tags: [].}
encodes s into base64 representation. After lineLen characters, a newline is added.
This procedure encodes a string.
proc decode(s: string): string {...}{.raises: [], tags: [].}
© 2006–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/base64.html