
Download content from the connector
Source:R/cnt_generics.R
, R/fs_methods.R
, R/logger_generics.R
download_cnt.Rd
Generic implementing of how to download files from a connector:
ConnectorFS: Uses
fs::file_copy()
to copy a file from the file storage to the desiredfile
.
ConnectorLogger: Logs the download operation and calls the underlying connector method.
Value
invisible connector_object.
Examples
# Download file from a file storage
folder <- withr::local_tempdir("test", .local_envir = .GlobalEnv)
cnt <- connector_fs(folder)
cnt |>
write_cnt("this is an example", "example.txt")
list.files(pattern = "example.txt")
#> character(0)
cnt |>
download_cnt("example.txt")
list.files(pattern = "example.txt")
#> [1] "example.txt"
readLines("example.txt")
#> [1] "this is an example"
cnt |>
remove_cnt("example.txt")
# Add logging to a file system connector for downloads
folder <- withr::local_tempdir("test", .local_envir = .GlobalEnv)
cnt <- connectors(data = connector_fs(folder)) |> add_logs()
cnt$data |>
write_cnt(iris, "iris.csv")
#> {"time":"2025-08-20 06:16:02","type":"write","file":"iris.csv @ /tmp/Rtmpp1dzyw/test1ebe13f98050"}
cnt$data |>
download_cnt("iris.csv", tempfile(fileext = ".csv"))
#> {"time":"2025-08-20 06:16:02","type":"read","file":"iris.csv @ /tmp/Rtmpp1dzyw/test1ebe13f98050"}