Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active August 29, 2015 14:17
Show Gist options
  • Save jeroen/b053fd18c8a8421d682f to your computer and use it in GitHub Desktop.
Save jeroen/b053fd18c8a8421d682f to your computer and use it in GitHub Desktop.
How to do stuff in curl
library(curl)
# Verbose
h <- new_handle()
handle_setopt(h, verbose = TRUE)
req <- curl_perform("http://httpbin.org/get", handle = h)
# Parsing headers
parse_headers(req$headers)
# Streaming with a callback function:
get_with_callback <- function(url, cb){
con <- curl(url)
open(con, "rb")
on.exit(close(con))
while(length(buf <- readBin(con, raw(), n = 8000))){
cb(buf)
}
invisible()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment