Title: | Tools for base64 Encoding |
---|---|
Description: | Tools for handling base64 encoding. It is more flexible than the orphaned base64 package. |
Authors: | Simon Urbanek <[email protected]> |
Maintainer: | Simon Urbanek <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 0.1-4 |
Built: | 2024-12-11 05:41:02 UTC |
Source: | https://github.com/s-u/base64enc |
base64encode
encodes a data into base64 encoding. The source
can be a file, binary connection or a raw vector.
base64decode
decodes a base64-encoded string into binary
data. The source can be a string or a connection, the output is
either a raw vector (output=NULL
) or a binary connection.
base64encode(what, linewidth, newline) base64decode(what, output = NULL, file)
base64encode(what, linewidth, newline) base64decode(what, output = NULL, file)
what |
data to be encoded/decoded. For |
linewidth |
if set, the output is split into lines with at most
|
newline |
only applicable if |
output |
if |
file |
file name (string) for data to use as input instead of
|
base64encode
: A character vector. If linewith > 0
and
newline
is not set then it will consist of as many elements
as there are lines. Otherwise it is a single string.
base64decode
: If output = NULL
then a raw vector with
the decoded content, otherwise the number of bytes written into the
connection.
Simon Urbanek
base64encode(1:100) base64encode(1:100, 70) base64encode(1:100, 70, "\n") x <- charToRaw("the decoded content, otherwise the number of bytes") y <- base64decode(base64encode(x)) stopifnot(identical(x, y))
base64encode(1:100) base64encode(1:100, 70) base64encode(1:100, 70, "\n") x <- charToRaw("the decoded content, otherwise the number of bytes") y <- base64decode(base64encode(x)) stopifnot(identical(x, y))
checkUTF8
check whether a given raw vector can be used as a
valid string encoded in UTF8.
checkUTF8(what, quiet = FALSE, charlen = FALSE, min.char = 1L)
checkUTF8(what, quiet = FALSE, charlen = FALSE, min.char = 1L)
what |
raw vector with the payload |
quiet |
logical, if |
charlen |
logical, if |
min.char |
integer, any bytes below this value are considered control chacters and reported as errors. The default value of 1L guards against strings including NULs. |
If charlen=FALSE
: TRUE
on success, FALSE
if the
payload is invalid and quite=TRUE
.
If charlen=TRUE
: positive integer corresponding to the
longest encoded sequence on success, negative integer on failure.
Simon Urbanek
dataURI
creates URI with the data:
scheme by encoding
the payload either using base64 ot URI encoding.
dataURI(data, mime = "", encoding = "base64", file)
dataURI(data, mime = "", encoding = "base64", file)
data |
raw vector, connection or character vector to use as
payload. Character vectors of more than one element are collapsed
using |
mime |
MIME-type of the data (per standard "" is interpreted as "text/plain;charset=US-ASCII" without including it in the URI) |
encoding |
data encoding to use. Must be either |
file |
filename (string) to open as payload. |
string of the form data:[mime][;base64],<encoded-payload>
Simon Urbanek
RFC 2397 The "data" URL scheme
dataURI(as.raw(1:10)) # default is base64 dataURI(as.raw(1:10), encoding=NULL) # URI if (require("png", quietly=TRUE)) { # let's say you have an image - e.g. from dev.capture(TRUE) img <- matrix(1:16/16, 4) dataURI(writePNG(img), "image/png") # or straight from a file dataURI(file=system.file("img", "Rlogo.png", package="png"), mime="image/png") }
dataURI(as.raw(1:10)) # default is base64 dataURI(as.raw(1:10), encoding=NULL) # URI if (require("png", quietly=TRUE)) { # let's say you have an image - e.g. from dev.capture(TRUE) img <- matrix(1:16/16, 4) dataURI(writePNG(img), "image/png") # or straight from a file dataURI(file=system.file("img", "Rlogo.png", package="png"), mime="image/png") }