encode: Encode and decode using base64

View source: R/encode.R

encodeR Documentation

Encode and decode using base64

Description

Encode and decode using base64

Usage

encode(what, eng = engine())

decode(what, eng = engine())

decode_as_string(what, newline = "\n", eng = engine())

encode_file(path, eng = engine())

decode_file(path, eng = engine())

Arguments

what

a character, raw, or blob vector

eng

a base64 engine. See engine() for details.

newline

a character sequence to split in the input base64 encoded string on before decoding.

path

a path to a base64 encoded file.

Details

Encoding

  • encode() takes a character vector, list of raw vectors (or blob class), or a raw vector and encodes them into base64 strings.

  • encode_file() takes a path to a file and encodes it as a base64 string.

Decoding

  • decode() will decode either a base64 encoded character scalar, a raw vector, or a list of raw vectors (see blob package).

  • decode_file() will decode a base64 encoded file into a raw vector.

  • decode_as_string() is designed to decode a base64 encoded string to a utf-8 string. By default, it will decode a chunked base64 encoded strings using ⁠\n⁠ as the separator. Use the newline argument to determine how to split the input string prior to decoding.

Value

Both encode() and decode() are vectorized. They will return a character and blob vector the same length as what, respectively.

decode_as_string() returns a character scalar.

Examples

# encode hello world
encoded <- encode("Hello world")
encoded

# decode to a blob
decoded <- decode(encoded)
decoded

# convert back to a character
rawToChar(decoded[[1]])

b64 documentation built on June 8, 2025, 10:32 a.m.