getBinaryURL              package:RCurl              R Documentation

_D_o_w_n_l_o_a_d _b_i_n_a_r_y _c_o_n_t_e_n_t

_D_e_s_c_r_i_p_t_i_o_n:

     This function allows one to download binary content. This is a
     convenience function that is a call to 'getURL' with suitable
     values for the 'write' and 'file' 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.

     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 'write' and 'file' in the call to 'curlPerform'.

_U_s_a_g_e:

     getBinaryURL(url, ..., .opts = list(), curl = getCurlHandle(), .buf = binaryBuffer(.len), .len = 5000)

_A_r_g_u_m_e_n_t_s:

     url: the URL identifying the content to download. This can be a
          regular URL or a 'application/x-www-form-urlencoded' URL,
          i.e. with name=value parameters appended to the location via
          a ?, and separated  from each other via a .

     ...: additional arguments that are passed to 'getURL'.

   .opts: a list of named values that are passed to 'getURL' as the
          '.opts' argument.

    curl: an optional curl handle used in 'curlPerform' 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.

    .buf: 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.

    .len: 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. 

_V_a_l_u_e:

     A "raw" vector.

_A_u_t_h_o_r(_s):

     Duncan Temple Lang

_S_e_e _A_l_s_o:

     'getURL' 'raw' 'gunzip'

_E_x_a_m_p_l_e_s:

       u = "http://www.omegahat.org/RCurl/data.gz"

       content = getBinaryURL(u)

       if(require(Rcompression)) {
         x = gunzip(content)
         read.csv(textConnection(x))
       } else {
          tmp = tempfile()
          write(content, file = tmp)
          read.csv(gzfile(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(require(Rcompression)) 
             x = gunzip(content)
       }

