Learn R Programming

azr (version 0.3.1)

api_storage_client: Azure Storage API Class

Description

An R6 class that extends api_client to provide specialized methods for Azure Data Lake Storage Gen2 (ADLS Gen2) REST API operations.

Arguments

Super class

azr::api_client -> api_storage_client

Public fields

.filesystem

The filesystem (container) name

Methods

Inherited methods


Method new()

Create a new Azure Storage API client instance

Usage

api_storage_client$new(
  storageaccount,
  filesystem,
  scopes = ".default",
  chain = NULL,
  tenant_id = NULL,
  ...
)

Arguments

storageaccount

A character string specifying the Azure Storage account name.

filesystem

A character string specifying the filesystem (container) name.

scopes

A character string specifying the OAuth2 scope suffix. Defaults to ".default", which requests all permissions the app has been granted.

chain

A credential_chain instance for authentication. If NULL, a default credential chain will be created using DefaultCredential.

tenant_id

A character string specifying the Azure tenant ID. Passed to DefaultCredential when chain is NULL.

...

Additional arguments passed to the parent api_client constructor.

Returns

A new api_storage_client object


Method download_file()

Download a file from the filesystem

Usage

api_storage_client$download_file(path, dest = NULL)

Arguments

path

A character string specifying the file path within the filesystem.

dest

A character string specifying the local destination path. Defaults to a temporary file via tempfile().

Returns

The local path the file was written to (invisibly).


Method get_access_control()

Get the access control list (ACL) for a file or directory

Usage

api_storage_client$get_access_control(dataset, upn = FALSE)

Arguments

dataset

A character string specifying the file or directory path within the filesystem.

upn

A logical value. If TRUE, user principal names (UPN) are returned in the x-ms-owner, x-ms-group, and x-ms-acl response headers instead of object IDs. Defaults to FALSE.

Returns

A data.frame with columns group_id and permission, one row per named group entry in the x-ms-acl response header.


Method list_files()

List files and directories in a path

Usage

api_storage_client$list_files(path = "", recursive = FALSE, ...)

Arguments

path

A character string specifying the directory path to list. Use empty string or NULL for the root directory. Defaults to "".

recursive

A logical value indicating whether to list files recursively. Defaults to FALSE.

...

Additional query parameters to pass to the API.

Returns

A data.frame (or data.table if available) containing file and directory information with columns such as name, contentLength, lastModified, etc.


Method clone()

The objects of this class are cloneable with this method.

Usage

api_storage_client$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

The base URL is constructed as: https://{storageaccount}.dfs.core.windows.net

Examples

Run this code
if (FALSE) {
# Create a storage client
storage <- api_storage_client$new(
  storageaccount = "mystorageaccount",
  filesystem = "mycontainer"
)

# List files in the root directory
files <- storage$list_files()

# List files in a specific path
files <- storage$list_files(path = "data/folder1")

# List files recursively
files <- storage$list_files(path = "data", recursive = TRUE)
}

Run the code above in your browser using DataLab