% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/download.R
\name{inmet_download}
\alias{inmet_download}
\title{Download INMET historical data ZIPs with resume support}
\usage{
inmet_download(
  years = as.integer(format(Sys.Date(), "\%Y")),
  dest_dir = tools::R_user_dir("rmet", "cache"),
  max_tries = 15L,
  quiet = FALSE,
  force = FALSE
)
}
\arguments{
\item{years}{Integer vector of years to download. Available years start from
2000. Defaults to the current year.}

\item{dest_dir}{Character. Directory where ZIP files will be saved.
Created automatically if it does not exist. Defaults to a persistent
cache directory under \code{tools::R_user_dir("rmet", "cache")}.}

\item{max_tries}{Integer. Maximum number of download attempts per year
before giving up. Defaults to \code{15}.}

\item{quiet}{Logical. If \code{TRUE}, suppresses progress messages.
Defaults to \code{FALSE}.}

\item{force}{Logical. If \code{TRUE}, deletes any existing (possibly partial)
ZIP before downloading. Defaults to \code{FALSE}.}
}
\value{
Invisibly returns a named character vector (class \code{character}) of
local file paths to the downloaded ZIP files. Names correspond to the
requested years (e.g., \code{"2023"}). Years that failed to download are
excluded. If all downloads fail, an empty named character vector is
returned.
}
\description{
Downloads one or more annual ZIP files from INMET's historical data portal.
Downloads are resumable: if a partial file is already on disk (e.g., from a
previous interrupted session), the function picks up where it left off
instead of restarting.
}
\details{
INMET's server sometimes drops connections mid-transfer. The function
handles this by using \code{curl}'s \code{CURLOPT_RESUME_FROM} to append to the
partial file on each retry, then validates the result with
\code{\link[utils:unzip]{utils::unzip()}}. A \code{Sys.sleep(5)} back-off separates retries.

ZIP files are \strong{not} extracted by this function. Use \code{\link[=inmet_read]{inmet_read()}} to
parse the contents directly from the ZIP, or \code{\link[=inmet_extract]{inmet_extract()}} to unzip
to a directory.
}
\examples{
\donttest{
paths <- inmet_download(years = 2000, dest_dir = tempdir())
}
}
\seealso{
\code{\link[=inmet_read]{inmet_read()}}, \code{\link[=inmet_extract]{inmet_extract()}}
}
