Skip to content

Instantly share code, notes, and snippets.

@timotheecour
Created December 2, 2020 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timotheecour/cdfa0d379d795006cf035c9309b27951 to your computer and use it in GitHub Desktop.
Save timotheecour/cdfa0d379d795006cf035c9309b27951 to your computer and use it in GitHub Desktop.
## Encoding data
## -------------
##
runnableExamples:
let encoded = encode("Hello World")
assert encoded == "SGVsbG8gV29ybGQ="
## Apart from strings you can also encode lists of integers or characters:
runnableExamples:
let encodedInts = encode([1,2,3])
assert encodedInts == "AQID"
let encodedChars = encode(['h','e','y'])
assert encodedChars == "aGV5"
## Decoding data
## -------------
##
runnableExamples:
let decoded = decode("SGVsbG8gV29ybGQ=")
assert decoded == "Hello World"
## URL Safe Base64
## ---------------
##
runnableExamples:
doAssert encode("c\xf7>", safe = true) == "Y_c-"
doAssert encode("c\xf7>", safe = false) == "Y/c+"
## See also
## ========
##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment