EVOLUTION-MANAGER
Edit File: getBinaryURL.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Download binary content</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for getBinaryURL {RCurl}"><tr><td>getBinaryURL {RCurl}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Download binary content</h2> <h3>Description</h3> <p>This function allows one to download binary content. This is a convenience function that is a call to <code><a href="getURL.html">getURL</a></code> with suitable values for the <code>write</code> and <code>file</code> options for the Curl handle. These take care of processing the body of the response to the Curl request into a vector of "raw" elements. </p> <p>Binary content from POST forms or other requests that are not simple URL requests can be implemented using the same approach as this function, i.e., specifying the same values as in the body of this function for <code>write</code> and <code>file</code> in the call to <code><a href="curlPerform.html">curlPerform</a></code>. </p> <h3>Usage</h3> <pre> getBinaryURL(url, ..., .opts = list(), curl = getCurlHandle(), .buf = binaryBuffer(.len), .len = 5000) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>url</code></td> <td> <p>the URL identifying the content to download. This can be a regular URL or a <code>application/x-www-form-urlencoded</code> URL, i.e. with name=value parameters appended to the location via a ?, and separated from each other via a \&.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>additional arguments that are passed to <code><a href="getURL.html">getURL</a></code>.</p> </td></tr> <tr valign="top"><td><code>.opts</code></td> <td> <p>a list of named values that are passed to <code><a href="getURL.html">getURL</a></code> as the <code>.opts</code> argument.</p> </td></tr> <tr valign="top"><td><code>curl</code></td> <td> <p>an optional curl handle used in <code><a href="curlPerform.html">curlPerform</a></code> that has been created previously and is to be reused for this request. This allows the R user to reuse a curl handle that already has a connection to the server or has settings for options that have been set previously.</p> </td></tr> <tr valign="top"><td><code>.buf</code></td> <td> <p>a raw vector in which to insert the body of the response. This is a parameter to allow the caller to reuse an existing buffer.</p> </td></tr> <tr valign="top"><td><code>.len</code></td> <td> <p>an non-negative integer which is used as the length for the buffer in which to store the binary data in the response. The buffer is extended if it is not big enough but this allows the caller to provide context specific knowledge about the length of the response, e.g. the size of the file being downloaded, and avoid expanding the buffer as the material is being processed. </p> </td></tr> </table> <h3>Value</h3> <p>A "raw" vector. </p> <h3>Author(s)</h3> <p>Duncan Temple Lang</p> <h3>See Also</h3> <p><code><a href="getURL.html">getURL</a></code>, <code><a href="../../base/html/raw.html">raw</a></code>, <code><a href="../../base/html/memCompress.html">memDecompress</a></code> </p> <h3>Examples</h3> <pre> u = "http://www.omegahat.net/RCurl/data.gz" if(url.exists(u)) withAutoprint({ content = getBinaryURL(u) if (getRversion() >= "4") withAutoprint({ x <- memDecompress(content, asChar = TRUE) read.csv(textConnection(x)) }) else withAutoprint({ tmp = tempfile() writeBin(content, con = tmp) read.csv(gzfile(tmp)) unlink(tmp) }) # Working from the Content-Type in the header of the HTTP response. h = basicTextGatherer() content = getBinaryURL(u, .opts = list(headerfunction = h$update)) header = parseHTTPHeader(h$value()) type = strsplit(header["Content-Type"], "/")[[1]] if(type[2] %in% c("x-gzip", "gzip")) { if (getRversion() >= "4") { cat(memDecompress(content, asChar = TRUE)) } else { tmp = tempfile() writeBin(content, con = tmp) writeLines(readLines(gzfile(tmp))) unlink(tmp) } } }) </pre> <hr /><div style="text-align: center;">[Package <em>RCurl</em> version 1.98-1.2 <a href="00Index.html">Index</a>]</div> </body></html>