Last active
August 29, 2015 14:08
-
-
Save jeroen/6fc584ea0a77bb66a533 to your computer and use it in GitHub Desktop.
curl() connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Synchronous implementation of curl() connection | |
| curl <- function(url){ | |
| con <- rawConnection(raw(0), "r+"); | |
| cat("Downloading ") | |
| req <- httr::GET(url, httr::write_stream(function(x){ | |
| cat(".") | |
| writeBin(x, con) | |
| })) | |
| httr::stop_for_status(req) | |
| seek(con, 0) | |
| con | |
| } | |
| # Does not parse-stream. Downloads all data first. | |
| diamonds <- jsonlite::stream_in(curl("https://jeroenooms.github.io/data/diamonds.json")) | |
| # Also does not support gzip | |
| flights <- jsonlite::stream_in(gzcon(curl("https://jeroenooms.github.io/data/flights.json.gz"))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is now possible with the new curl package.