Title: Fast and Vectorized Base 64 Engine
Version: 0.1.7
Description: Provides a fast, lightweight, and vectorized base 64 engine to encode and decode character and raw vectors as well as files stored on disk. Common base 64 alphabets are supported out of the box including the standard, URL-safe, bcrypt, crypt, 'BinHex', and IMAP-modified UTF-7 alphabets. Custom engines can be created to support unique base 64 encoding and decoding needs.
License: MIT + file LICENSE
Encoding: UTF-8
Language: en
RoxygenNote: 7.3.2
Config/rextendr/version: 0.4.0.9000
SystemRequirements: Cargo (Rust's package manager), rustc, xz
Suggests: blob, testthat (≥ 3.0.0)
Config/testthat/edition: 3
URL: https://extendr.github.io/b64/, https://github.com/extendr/b64
BugReports: https://github.com/extendr/b64/issues
Depends: R (≥ 4.2)
NeedsCompilation: yes
Packaged: 2025-07-14 16:06:04 UTC; josiahparry
Author: Josiah Parry ORCID iD [aut, cre], Etienne Bacher ORCID iD [ctb]
Maintainer: Josiah Parry <josiah.parry@gmail.com>
Repository: CRAN
Date/Publication: 2025-07-14 16:30:06 UTC

b64: Fast and Vectorized Base 64 Engine

Description

Provides a fast, lightweight, and vectorized base 64 engine to encode and decode character and raw vectors as well as files stored on disk. Common base 64 alphabets are supported out of the box including the standard, URL-safe, bcrypt, crypt, 'BinHex', and IMAP-modified UTF-7 alphabets. Custom engines can be created to support unique base 64 encoding and decoding needs.

Author(s)

Maintainer: Josiah Parry josiah.parry@gmail.com (ORCID)

Other contributors:

See Also

Useful links:


Standard base64 alphabets

Description

Create an alphabet from a set of standard base64 alphabets, or use your own.

Usage

alphabet(which = "standard")

new_alphabet(chars)

Arguments

which

default "standard". Which base64 alphabet to use. See details for other values.

chars

a character scalar contains 64 unique characters.

Details

See base64 crate from where these definitions come.

Value

an object of class alphabet

Examples

alphabet("standard")
alphabet("bcrypt")
alphabet("bin_hex")
alphabet("crypt")
alphabet("imap_mutf7")
alphabet("url_safe")

new_alphabet("qwertyuiop[]asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890")

Utility Functions

Description

Functions to perform common tasks when working with base64 encoded strings.

Usage

b64_chunk(encoded, width)

b64_wrap(chunks, newline)

Arguments

encoded

a character vector of base64 encoded strings.

width

a numeric scalar defining the width of the chunks. Must be divisible by 4.

chunks

a character vector of base64 encoded strings.

newline

a character scalar defining the newline character.

Details

b64_chunk() splits a character vector of base64 encoded strings into chunks of a specified width.

b64_wrap() wraps a character vector of base64 encoded strings with a newline character.

Value

Examples

encoded <- encode("Hello, world!")
chunked <- b64_chunk(encoded, 4)
chunked

b64_wrap(chunked, "\n")

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

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]])

Create an encoding engine

Description

Create an encoding engine

Usage

engine(which = "standard")

new_engine(.alphabet = alphabet(), .config = new_config())

Arguments

which

default "standard". The base64 encoding engine to be used. See details for more.

.alphabet

an object of class alphabet as created with alphabet() or new_alphabet()

.config

an object of class engine_config as created with new_config()

Details

Engines

By default, the "standard" base64 engine is used which is specified in RFC 4648.

Additional pre-configured base64 engines are provided these are:

See base64 crate for more.

Value

an object of class engine.

Examples

engine()
new_engine(alphabet("bcrypt"), new_config())

Create a custom encoding engine

Description

Create a custom encoding engine

Usage

new_config(
  encode_padding = TRUE,
  decode_padding_trailing_bits = FALSE,
  decode_padding_mode = c("canonical", "indifferent", "none")
)

Arguments

encode_padding

default TRUE add 1-2 trailing = to pad results

decode_padding_trailing_bits

default FALSE. "If invalid trailing bits are present and this is true, those bits will be silently ignored." (See details for reference).

decode_padding_mode

default "canonical". Other values are "indifferent" and "none". See details for more.

Details

See base64 crate for more details.

Decode Padding Modes

There are three modes that can be used for decode_padding_mode argument.

Value

an object of class engine_config

Examples

# create a new nonsensicle config
new_config(FALSE, TRUE, "none")