| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/cache.R |
| 3 |
\name{download_cache} |
| 4 |
\alias{download_cache} |
| 5 |
\title{Download a file from a URL and cache it on disk} |
| 6 |
\format{ |
| 7 |
A list of methods: |
| 8 |
\itemize{ |
| 9 |
\item \verb{$get(url, type, handler)} downloads a URL, caches it, and returns the file |
| 10 |
content according to the value of \code{type} (possible values: \code{"text"} means |
| 11 |
the text content; \code{"base64"} means the base64 encoded data; \code{"raw"} means |
| 12 |
the raw binary content; \code{"auto"} is the default and means the type is |
| 13 |
determined by the content type in the URL headers). Optionally a \code{handler} |
| 14 |
function can be applied to the content. |
| 15 |
\item \verb{$list()} gives the list of cache files. |
| 16 |
\item \verb{$summary()} gives a summary of existing cache files. |
| 17 |
\item \verb{$remove(url, type)} removes a single cache file. |
| 18 |
\item \verb{$purge()} deletes all cache files. |
| 19 |
} |
| 20 |
} |
| 21 |
\usage{ |
| 22 |
download_cache |
| 23 |
} |
| 24 |
\description{ |
| 25 |
This object provides methods to download files and cache them on disk. |
| 26 |
} |
| 27 |
\examples{\dontshow{if (interactive()) \{} |
| 28 |
# the first time it may take a few seconds |
| 29 |
x1 = xfun::download_cache$get("https://www.r-project.org/") |
| 30 |
head(x1) |
| 31 |
|
| 32 |
# now you can get the cached content |
| 33 |
x2 = xfun::download_cache$get("https://www.r-project.org/") |
| 34 |
identical(x1, x2) # TRUE |
| 35 |
|
| 36 |
# a binary file |
| 37 |
x3 = xfun::download_cache$get("https://yihui.org/images/logo.png", "raw") |
| 38 |
length(x3) |
| 39 |
|
| 40 |
# show a summary |
| 41 |
xfun::download_cache$summary() |
| 42 |
# remove a specific cache file |
| 43 |
xfun::download_cache$remove("https://yihui.org/images/logo.png", "raw") |
| 44 |
# remove all cache files |
| 45 |
xfun::download_cache$purge() |
| 46 |
\dontshow{\}} |
| 47 |
} |