-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathhelpers.R
21 lines (21 loc) · 966 Bytes
/
helpers.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#' write base64 result to file
#'
#' This is a helper function to write some resulting data from chrome to file.
#' It will:
#' - decode the base64 encoded raw data
#' - write to file using [base::writeBin()][base::readBin()]
#' It will be useful for function like [`Page$printToPDF()`](https://chromedevtools.github.io/devtools-protocol/tot/Page#method-printToPDF)
#'
#' @param res A resulting list object with some `data` field containing base64
#' encoded data. (like [`Page$printToPDF()`](https://chromedevtools.github.io/devtools-protocol/tot/Page#method-printToPDF))
#' @param con A [connection][base::connections] object. See [base::writeBin()][base::readBin()].
#'
#' @export
#'
#' @importFrom jsonlite base64_dec
write_base64 <- function(res, con) {
assertthat::assert_that(assertthat::has_name(res, "data"))
assertthat::assert_that(assertthat::is.string(res$data))
decoded_res <- jsonlite::base64_dec(res$data)
writeBin(decoded_res, con = con)
}