Skip to contents

Generic implementing of how to download files from a connector:

  • ConnectorLogger: Logs the download operation and calls the underlying connector method.

Usage

download_cnt(connector_object, src, dest = basename(src), ...)

# S3 method for class 'ConnectorFS'
download_cnt(connector_object, src, dest = basename(src), ...)

# S3 method for class 'ConnectorLogger'
download_cnt(connector_object, src, dest = basename(src), ...)

Arguments

connector_object

Connector The connector object to use.

src

character Name of the content to read, write, or remove. Typically the table name.

dest

character Path to the file to download to or upload from

...

Additional arguments passed to the method for the individual connector.

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"}