Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ Imports:
utils,
tools,
curl,
httr,
httr2,
xml2 (> 1.0.0),
base64enc,
digest,
aws.signature (>= 0.3.7)
Suggests:
testthat,
datasets
RoxygenNote: 7.1.0
RoxygenNote: 7.3.2
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export(save_object)
export(saveobject)
export(select_object)
import(aws.signature)
import(httr)
import(httr2)
importFrom(base64enc,base64encode)
importFrom(curl,curl)
importFrom(curl,handle_setheaders)
Expand Down
2 changes: 1 addition & 1 deletion R/acl.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ get_acl <- function(object, bucket, ...) {
parse_response = FALSE,
...)
}
return(content(r, "text", encoding = "UTF-8"))
return(httr2::resp_body_string(r, "UTF-8"))
}

#' @rdname acl
Expand Down
34 changes: 27 additions & 7 deletions R/get_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#' @param request_body For \code{select_object}, an XML request body as described in the \href{https://docs.aws.amazon.com/AmazonS3/latest/API/API_SelectObjectContent.html}{SELECT API documentation}.
#' @param headers List of request headers for the REST call.
#' @param parse_response Passed through to \code{\link{s3HTTP}}, as this function requires a non-default setting. There is probably no reason to ever change this.
#' @param as Passed through to \code{httr::content}.
#' @param as Should be one of `"raw"` (returns a vector of `raw` data),
#' `"text"` (returns a `character` string), or `"parsed"`. The latter will
#' attempt to parse the content to an appropriate R object.
#' @template dots
#' @details \code{get_object} retrieves an object into memory as a raw vector. This page describes \code{get_object} and several wrappers that provide additional useful functionality.
#'
Expand Down Expand Up @@ -92,12 +94,29 @@ function(object,
headers = headers,
parse_response = parse_response,
...)
cont <- httr::content(r, as = as)
cont <-
switch(
as,
text = { httr2::resp_body_string(r) },
raw = { httr2::resp_body_raw(r) },
parsed = {
ctype <- httr2::resp_content_type(r)
switch(
ctype,
`application/json` = { httr2::resp_body_json(r) },
`text/xml` = { httr2::resp_body_xml() },
`application/xml` = { httr2::resp_body_xml() },
`text/html` = { httr2::resp_body_html() },
{ httr2::resp_body_raw() },
)
},
{ httr2::resp_body_raw() }
)
return(cont)
}

#' @rdname get_object
#' @param overwrite A logical indicating whether to overwrite \code{file}. Passed to \code{\link[httr]{write_disk}}. Default is \code{TRUE}.
#' @param overwrite A logical indicating whether to overwrite \code{file}.
#' @export
save_object <-
function(object,
Expand All @@ -117,12 +136,13 @@ function(object,
dir.create(d, recursive = TRUE)
}

# use httr::write_disk() to write directly to disk
if (!overwrite && file.exists(file))
stop(sprintf("File '%s' already exists. Set 'overwrite' to TRUE, to overwrite"))
r <- s3HTTP(verb = "GET",
bucket = bucket,
path = paste0("/", object),
headers = headers,
write_disk = httr::write_disk(path = file, overwrite = overwrite),
file = file,
...)
return(file)
}
Expand Down Expand Up @@ -151,7 +171,7 @@ function(
request_body = request_body,
parse_response = parse_response,
...)
cont <- httr::content(r, as = "raw")
cont <- httr2::resp_body_raw(r)
return(cont)
}

Expand All @@ -175,7 +195,7 @@ get_torrent <- function(object, bucket, ...) {
path = paste0("/", object),
query = list(torrent =""),
...)
return(content(r, "raw"))
return(httr2::resp_body_raw(r))
}

#' @rdname get_object
Expand Down
2 changes: 1 addition & 1 deletion R/policy.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ get_bucket_policy <- function(bucket, parse_response = TRUE, ...){
parse_response = FALSE,
...)
if (isTRUE(parse_response)) {
r <- httr::content(r, "text", encoding = "UTF-8")
r <- httr2::resp_body_string(r, "UTF-8")
}
return(r)
}
Expand Down
3 changes: 2 additions & 1 deletion R/put_object.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ function(
if (!is.na(size) && size > partsize)
message("File size is ", size, ", consider setting using multipart=TRUE")

## httr doesn't support connections so we have to read it all into memory first
## httr2 doesn't support connections as request body,
## so we have to read it all into memory first
if (inherits(what, "connection")) {
con <- what
if (!isOpen(con, "r"))
Expand Down
Loading