File: saveURI.R

package info (click to toggle)
rgl 1.3.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,968 kB
  • sloc: cpp: 23,234; ansic: 7,462; javascript: 6,125; sh: 3,555; makefile: 2
file content (12 lines) | stat: -rw-r--r-- 408 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
saveURI <- function(uri, con) {
  if (!grepl("^data:", uri))
    stop("Does not appear to be a data URI")
  header <- sub(",.*", "", uri)
  type <- sub(";.*", "", sub("^data:", "", header))
  encoding <- sub("^.*;", "", header)
  if (encoding != "base64")
    stop("Not encoded in base64")
  payload <- sub(paste0(header, ","), "", uri, fixed = TRUE)
  writeBin(base64_dec(payload), con)
  invisible(type)
}