зеркало из https://github.com/Azure/AzureStor.git
Added ability to check if a blob exists (#34)
* Added ability to check if a blob exists * Fixing Rd file * Fixing Rd file
This commit is contained in:
Родитель
e83a2ebfde
Коммит
b8e089742b
|
@ -99,6 +99,7 @@ export(break_lease)
|
|||
export(call_azcopy)
|
||||
export(call_storage_endpoint)
|
||||
export(change_lease)
|
||||
export(check_blob)
|
||||
export(copy_url_to_blob)
|
||||
export(copy_url_to_storage)
|
||||
export(create_adls_dir)
|
||||
|
|
|
@ -215,7 +215,7 @@ delete_blob_container.blob_endpoint <- function(endpoint, name, confirm=TRUE, le
|
|||
|
||||
#' Operations on a blob container or blob
|
||||
#'
|
||||
#' Upload, download, or delete a blob; list blobs in a container.
|
||||
#' Upload, download, or delete a blob; list blobs in a container; check blob availability.
|
||||
#'
|
||||
#' @param container A blob container object.
|
||||
#' @param blob A string naming a blob.
|
||||
|
@ -242,7 +242,7 @@ delete_blob_container.blob_endpoint <- function(endpoint, name, confirm=TRUE, le
|
|||
#' `upload_blob` and `download_blob` can display a progress bar to track the file transfer. You can control whether to display this with `options(azure_storage_progress_bar=TRUE|FALSE)`; the default is TRUE.
|
||||
#'
|
||||
#' @return
|
||||
#' For `list_blobs`, details on the blobs in the container. For `download_blob`, if `dest=NULL`, the contents of the downloaded blob as a raw vector.
|
||||
#' For `list_blobs`, details on the blobs in the container. For `download_blob`, if `dest=NULL`, the contents of the downloaded blob as a raw vector. For `check_blob` a flag whether the blob exists.
|
||||
#'
|
||||
#' @seealso
|
||||
#' [blob_container], [az_storage], [storage_download], [call_azcopy]
|
||||
|
@ -419,4 +419,14 @@ delete_blob <- function(container, blob, confirm=TRUE)
|
|||
invisible(do_container_op(container, blob, http_verb="DELETE"))
|
||||
}
|
||||
|
||||
|
||||
#' @rdname blob
|
||||
#' @export
|
||||
check_blob <- function(container, blob)
|
||||
{
|
||||
res <- do_container_op(container, blob, headers = list(), http_verb = "HEAD", http_status_handler = "pass")
|
||||
if (httr::status_code(res) == 404L) {
|
||||
return(FALSE)
|
||||
}
|
||||
httr::stop_for_status(res, storage_error_message(res))
|
||||
return(TRUE)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
\alias{upload_blob}
|
||||
\alias{multiupload_blob}
|
||||
\alias{download_blob}
|
||||
\alias{check_blob}
|
||||
\alias{multidownload_blob}
|
||||
\alias{delete_blob}
|
||||
\alias{copy_url_to_blob}
|
||||
|
@ -30,6 +31,8 @@ multidownload_blob(container, src, dest, recursive = FALSE,
|
|||
|
||||
delete_blob(container, blob, confirm = TRUE)
|
||||
|
||||
check_blob(container, blob)
|
||||
|
||||
copy_url_to_blob(container, src, dest, lease = NULL, async = FALSE)
|
||||
|
||||
multicopy_url_to_blob(container, src, dest, lease = NULL,
|
||||
|
@ -67,10 +70,10 @@ multicopy_url_to_blob(container, src, dest, lease = NULL,
|
|||
\item{async}{For \code{copy_url_to_blob} and \code{multicopy_url_to_blob}, whether the copy operation should be asynchronous (proceed in the background).}
|
||||
}
|
||||
\value{
|
||||
For \code{list_blobs}, details on the blobs in the container. For \code{download_blob}, if \code{dest=NULL}, the contents of the downloaded blob as a raw vector.
|
||||
For \code{list_blobs}, details on the blobs in the container. For \code{download_blob}, if \code{dest=NULL}, the contents of the downloaded blob as a raw vector. For \code{check_blob} a flag whether the blob exists.
|
||||
}
|
||||
\description{
|
||||
Upload, download, or delete a blob; list blobs in a container.
|
||||
Upload, download, or delete a blob; list blobs in a container; check blob availability.
|
||||
}
|
||||
\details{
|
||||
\code{upload_blob} and \code{download_blob} are the workhorse file transfer functions for blobs. They each take as inputs a \emph{single} filename as the source for uploading/downloading, and a single filename as the destination. Alternatively, for uploading, \code{src} can be a \link{textConnection} or \link{rawConnection} object; and for downloading, \code{dest} can be NULL or a \code{rawConnection} object. If \code{dest} is NULL, the downloaded data is returned as a raw vector, and if a raw connection, it will be placed into the connection. See the examples below.
|
||||
|
|
|
@ -134,6 +134,10 @@ test_that("Blob client interface works",
|
|||
iris3 <- as.data.frame(jsonlite::fromJSON(con))
|
||||
expect_identical(iris, iris3)
|
||||
|
||||
# check blob
|
||||
expect_false(check_blob(cont, "nonexisting.blob"))
|
||||
expect_true(check_blob(cont, "iris.json"))
|
||||
|
||||
# ways of deleting a container
|
||||
delete_blob_container(cont, confirm=FALSE)
|
||||
delete_blob_container(bl, "newcontainer2", confirm=FALSE)
|
||||
|
|
Загрузка…
Ссылка в новой задаче