Skip to content
Snippets Groups Projects

final changes to ask_GET, zip files handled as text files

Merged Marek Ostaszewski requested to merge Rcode into master
1 file
+ 6
3
Compare changes
  • Side-by-side
  • Inline
+ 6
3
@@ -30,13 +30,16 @@ ask_GET <- function(api_call, token = NULL, ctype = NULL,
### when the content is sent as a zip file, it needs to be handled differently,
### i.e. saved to a tmp file and unzipped
if(httr::headers(resp)$`content-type` == "application/zip") {
### Create a temp file and save the zip content there
tmp <- tempfile()
tmpc <- file(tmp, "wb")
writeBin(httr::content(resp, as = "raw"), con = tmpc)
close(tmpc)
unzipped <- utils::unzip(tmp)
file.remove(tmp)
return(unzipped)
### Unzip the content and read it in to return it, clean temp files
utmp <- utils::unzip(tmp)
ucontent <- readChar(utmp, file.info(utmp)$size)
file.remove(tmp, utmp)
return(ucontent)
} else {
return(httr::content(resp, as = "text", encoding = encoding))
}
Loading