@@ -49,6 +49,9 @@ db_workspace_delete <- function(path, recursive = FALSE,
4949# '
5050# ' @param format One of `AUTO`, `SOURCE`, `HTML`, `JUPYTER`, `DBC`, `R_MARKDOWN`.
5151# ' Default is `SOURCE`.
52+ # ' @param output_path Path to export file to, ensure to include correct suffix.
53+ # ' @param direct_download Boolean (default: `FALSE`), if `TRUE` download file
54+ # ' contents directly to file. Must also specify `output_path`.
5255# ' @inheritParams auth_params
5356# ' @inheritParams db_workspace_delete
5457# ' @inheritParams db_sql_warehouse_create
@@ -73,15 +76,16 @@ db_workspace_delete <- function(path, recursive = FALSE,
7376db_workspace_export <- function (path ,
7477 format = c(" AUTO" , " SOURCE" , " HTML" , " JUPYTER" , " DBC" , " R_MARKDOWN" ),
7578 host = db_host(), token = db_token(),
79+ output_path = NULL ,
80+ direct_download = FALSE ,
7681 perform_request = TRUE ) {
7782
78- # TODO
79- # do not support direct_download being TRUE currently
80- # need to make a decision as to if we expect to support saving direct to file
81- # gut feel is yes but want to think about it a bit more
82- direct_download <- FALSE
83-
8483 format <- match.arg(format , several.ok = FALSE )
84+ stopifnot(is.logical(direct_download ))
85+
86+ if (direct_download ) {
87+ stopifnot(! is.null(output_path ))
88+ }
8589
8690 body <- list (
8791 path = path ,
@@ -99,7 +103,14 @@ db_workspace_export <- function(path,
99103 )
100104
101105 if (perform_request ) {
102- db_perform_request(req )
106+ if (direct_download ) {
107+ req | >
108+ httr2 :: req_perform() | >
109+ httr2 :: resp_body_raw() | >
110+ base :: writeBin(con = output_path )
111+ } else {
112+ db_perform_request(req )
113+ }
103114 } else {
104115 req
105116 }
0 commit comments