
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()
cnt <- connector_fs(folder)
cnt |>
write_cnt("this is an example", "example.txt")
#> Error: Cannot open file for writing:
#> * '/tmp/RtmpnpFke0/file2106294e5648/example.txt'
list.files(pattern = "example.txt")
#> character(0)
cnt |>
download_cnt("example.txt")
#> Error: [ENOENT] Failed to copy '/tmp/RtmpnpFke0/file2106294e5648/example.txt' to 'example.txt': no such file or directory
list.files(pattern = "example.txt")
#> character(0)
readLines("example.txt")
#> Warning: cannot open file 'example.txt': No such file or directory
#> Error in file(con, "r"): cannot open the connection
cnt |>
remove_cnt("example.txt")
#> Error: [ENOENT] Failed to remove '/tmp/RtmpnpFke0/file2106294e5648/example.txt': no such file or directory
# Add logging to a file system connector for downloads
folder <- withr::local_tempdir()
cnt <- connectors(data = connector_fs(folder)) |> add_logs()
cnt$data |>
write_cnt(iris, "iris.csv")
#> Error: Cannot open file for writing:
#> * '/tmp/RtmpnpFke0/file2106556fbd37/iris.csv'
cnt$data |>
download_cnt("iris.csv", tempfile(fileext = ".csv"))
#> Error: [ENOENT] Failed to copy '/tmp/RtmpnpFke0/file2106556fbd37/iris.csv' to '/tmp/RtmpnpFke0/file21063ff76d27.csv': no such file or directory