Encodes / decodes a character string or arbitrary R object to base64 encoding.
base64enc(x, convert = TRUE)
base64dec(x, convert = TRUE)
an object.
[default TRUE] logical value whether to convert the output to a character string or keep as a raw vector. Supplying a non-logical value will error.
A raw vector or character string depending on 'convert'.
For encoding: a raw vector is encoded directly, a scalar character string is translated to raw before encoding, whilst all other objects are serialised first.
The result of encoding or decoding is always a raw vector, which is translated to a character string if 'convert' is TRUE, or returned directly if 'convert' is FALSE.
Set 'convert' to FALSE when decoding a raw vector or serialised object,
which may be further passed to unserialize
.
base64enc("hello world!")
#> [1] "aGVsbG8gd29ybGQh"
base64dec(base64enc("hello world!"))
#> [1] "hello world!"
base64enc("hello world!", convert = FALSE)
#> [1] 61 47 56 73 62 47 38 67 64 32 39 79 62 47 51 68
base64dec(base64enc("hello world!", convert = FALSE))
#> [1] "hello world!"
base64enc(data.frame())
#> [1] "WAoAAAADAAQDAAADBQAAAAAFVVRGLTgAAAMTAAAAAAAABAIAAAABAAQACQAAAAVuYW1lcwAAABAAAAAAAAAEAgAAAAEABAAJAAAACXJvdy5uYW1lcwAAAA0AAAAAAAAEAgAAAAEABAAJAAAABWNsYXNzAAAAEAAAAAEABAAJAAAACmRhdGEuZnJhbWUAAAD+"
unserialize(base64dec(base64enc(data.frame()), convert = FALSE))
#> data frame with 0 columns and 0 rows