download_if_needed#
- download_if_needed(uri: str, download_dir: str | None = None, fs: rastervision.pipeline.file_system.file_system.FileSystem | None = None, use_cache: bool = True) str[source]#
Download a file to a directory if remote and return its local path.
The full local path, within
download_dir, is determined byget_local_path(). If a file doesn’t already exists at that path, it is downloaded.- Parameters
uri (str) – URI of file to download. If this is a local path, it will be returned as is.
download_dir (str | None) – Local directory to download file into. If
None, the file will be downloaded to cache dir as defined byRVConfig. Defaults toNone.fs (rastervision.pipeline.file_system.file_system.FileSystem | None) – If provided, use
fsinstead of the automatically chosenFileSystemforuri. Defaults toNone.use_cache (bool) – If
Falseand the file is remote, download it regardless of whether it exists in cache. Defaults toTrue.
- Returns
Local path to file.
- Raises
NotReadableError – if URI cannot be read from.
- Return type