File: binaryBuffer.Rd

package info (click to toggle)
r-cran-rcurl 1.95-4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,140 kB
  • ctags: 515
  • sloc: ansic: 3,135; xml: 1,734; asm: 993; sh: 12; makefile: 2
file content (72 lines) | stat: -rw-r--r-- 2,587 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
\name{binaryBuffer}
\alias{binaryBuffer}
\alias{coerce,RCurlBinaryBuffer,raw-method}
\title{Create internal C-level data structure for collecting binary data}
\description{
  This is the constructor function for creating an internal data
  structure
  that is used when reading binary data from an HTTP request
  via RCurl.  It is used with the native routine
  \code{R_curl_write_binary_data} for collecting
  the response from the HTTP query into a buffer that stores
  the bytes. The contents can then be brought back into R
  as a \code{raw} vector and then used in different ways,
  e.g. uncompressed with the \code{Rcompression} package,
  or written to a file via \code{\link[base]{writeBin}}.
}
\usage{
binaryBuffer(initialSize = 5000)
}
\arguments{
  \item{initialSize}{a number giving the size (number of bytes) to
    allocate for the buffer. In most cases, the size won't make an
    enormous difference. If this is small, the
    \code{R_curl_write_binary_data} routine will expand it as necessary
    when more daat is received than would fit in it.  If it is very
    large, i.e. larger than the resulting response, the consequence is
    simply unused memory.   One can determine the appropriate size by
     performing the HTTP request with \code{nobody = TRUE} and looking
     at the resulting size indicated by the headers of the response,
     i.e.
     \code{getCurlInfo(handle)} and then using that size and repeating
     the request and receiving the body. This is a trade-off between
     network speed and memor consumption and processing speed when
     collecting the .
   }
}

\value{
  An object of class \code{RCurlBinaryBuffer} which is to be treated
  as an opaque data for the most part. When passing this as the value of
  the \code{file} option, one will have to pass the ref slot.

  After the contents have been read, one can convert this object to an R
  raw vector using \code{as(buf, "raw")}.
}
\references{Curl homepage \url{http://curl.haxx.se}}
\author{Duncan Temple Lang <duncan@wald.ucdavis.edu>}

\seealso{
 \code{R_curl_write_binary_data}
}
\examples{
if(url.exists("http://www.omegahat.net/RCurl/xmlParse.html.gz")) {
  buf = binaryBuffer()

     # Now fetch the binary file.
  getURI("http://www.omegahat.net/RCurl/xmlParse.html.gz",
         write = getNativeSymbolInfo("R_curl_write_binary_data")$address,
         file = buf@ref)

   # Convert the internal data structure into an R raw vector
  b = as(buf, "raw")

 if(require(Rcompression)) 
   gunzip(b)
 }
}
\keyword{IO}
\keyword{programming}
\concept{Web}
\concept{binary data}