AzureStor/R/blob_copyurl.R

81 строка
2.6 KiB
R
Исходник Обычный вид История

2019-07-18 06:29:28 +03:00
#' @details
#' `copy_url_to_storage` transfers the contents of the file at the specified HTTP\[S\] URL directly to storage, without requiring a temporary local copy to be made. `multicopy_url_to_storage` does the same, for multiple URLs at once. Currently methods for these are only implemented for blob storage.
2019-07-18 06:29:28 +03:00
#' @rdname file_transfer
#' @export
copy_url_to_storage <- function(container, src, dest, ...)
{
2019-10-30 18:50:57 +03:00
UseMethod("copy_url_to_storage")
2019-07-18 06:29:28 +03:00
}
#' @rdname file_transfer
#' @export
multicopy_url_to_storage <- function(container, src, dest, ...)
{
2019-10-30 18:50:57 +03:00
UseMethod("multicopy_url_to_storage")
}
2019-07-18 06:29:28 +03:00
#' @rdname file_transfer
#' @export
copy_url_to_storage.blob_container <- function(container, src, dest, ...)
{
copy_url_to_blob(container, src, dest, ...)
}
#' @rdname file_transfer
#' @export
multicopy_url_to_storage.blob_container <- function(container, src, dest, ...)
{
multicopy_url_to_blob(container, src, dest, ...)
}
#' @param async For `copy_url_to_blob` and `multicopy_url_to_blob`, whether the copy operation should be asynchronous (proceed in the background).
2019-07-18 06:29:28 +03:00
#' @details
2019-11-01 19:46:22 +03:00
#' `copy_url_to_blob` transfers the contents of the file at the specified HTTP\[S\] URL directly to blob storage, without requiring a temporary local copy to be made. `multicopy_url_to_blob` does the same, for multiple URLs at once. These functions have a current file size limit of 256MB.
2019-07-18 06:29:28 +03:00
#' @rdname blob
#' @export
copy_url_to_blob <- function(container, src, dest, lease=NULL, async=FALSE)
{
if(!is_url(src))
stop("Source must be a HTTP[S] url", call.=FALSE)
headers <- list(
`x-ms-copy-source`=src,
`x-ms-requires-sync`=!async
)
if(!is.null(lease))
headers[["x-ms-lease-id"]] <- as.character(lease)
do_container_op(container, dest, headers=headers, http_verb="PUT")
2019-10-30 17:43:41 +03:00
invisible(NULL)
2019-07-18 06:29:28 +03:00
}
#' @rdname blob
#' @export
2019-10-30 20:31:19 +03:00
multicopy_url_to_blob <- function(container, src, dest, lease=NULL, async=FALSE, max_concurrent_transfers=10)
{
2019-10-30 20:31:19 +03:00
if(missing(dest))
dest <- basename(src)
2019-10-30 18:50:57 +03:00
n_src <- length(src)
n_dest <- length(dest)
2019-10-30 18:50:57 +03:00
if(n_src == 0)
stop("No files to transfer", call.=FALSE)
if(n_dest != n_src)
stop("'dest' must contain one name per file in 'src'", call.=FALSE)
if(n_src == 1)
2019-11-01 19:46:22 +03:00
return(copy_url_to_blob(container, src, dest, lease=lease, async=async))
init_pool(max_concurrent_transfers)
2019-10-30 18:50:57 +03:00
pool_export("container", envir=environment())
2019-11-01 19:46:22 +03:00
pool_map(function(s, d, lease, async) AzureStor::copy_url_to_blob(container, s, d, lease=lease, async=async),
2019-10-30 18:50:57 +03:00
src, dest, MoreArgs=list(lease=lease, async=async))
invisible(NULL)
}