azblob

package
v0.1.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountRole added in v0.1.19

func AccountRole(account string) (string, bool)

AccountRole returns the role ("SRC" or "DST") registered for the given account, and a boolean indicating whether a role was registered.

func ClearAccountRole added in v0.1.19

func ClearAccountRole(account string)

ClearAccountRole removes the role registration and invalidates cached blob clients and delegation credentials created while that registration was active.

func CopyBlobFromURLServerSide added in v0.1.25

func CopyBlobFromURLServerSide(ctx context.Context, dst AzurePath, sourceURL string, size int64, concurrency int, onProgress CopyProgress) error

CopyBlobFromURLServerSide copies an external, publicly-readable HTTP(S) source URL directly into an Azure blob without streaming the bytes through this client. It is used for cross-backend server-side copy (e.g. Hugging Face → Azure), where the source URL is a public/signed CDN URL.

size is the exact source size in bytes when known; pass a negative value when the size is unknown. A known size uses the parallel StageBlockFromURL + CommitBlockList path (which must plan block IDs up front); an unknown size routes to Azure's async StartCopyFromURL, which transfers the whole blob server-side without a pre-known size.

func CopyBlobServerSide added in v0.1.12

func CopyBlobServerSide(ctx context.Context, src AzurePath, dst AzurePath, concurrency int, sizeHint int64, onProgress CopyProgress) error

func Delete

func Delete(ctx context.Context, ap AzurePath) error

Delete deletes a single blob

func DeletePrefix

func DeletePrefix(ctx context.Context, ap AzurePath) error

DeletePrefix deletes all blobs under directory-like path

func Download

func Download(ctx context.Context, ap AzurePath) ([]byte, error)

Download returns blob content bytes (for small blobs)

func DownloadFile added in v0.1.22

func DownloadFile(ctx context.Context, ap AzurePath, file *os.File, concurrency int, onProgress func(int64)) (int64, error)

DownloadFile downloads a blob to a local file using parallel ranged GETs. concurrency is the initial parallelism (and floor); an adaptive controller probes higher concurrency while throughput keeps improving, up to downloadHardConcurrencyCap (overridable via BBB_AZBLOB_DOWNLOAD_CONCURRENCY_MAX). The optional onProgress callback receives the cumulative number of bytes written. Returns the number of bytes downloaded.

func DownloadStream added in v0.1.8

func DownloadStream(ctx context.Context, ap AzurePath) (io.ReadCloser, error)

func HeadBlob

func HeadBlob(ctx context.Context, ap AzurePath) (int64, error)

HeadBlob returns size (bytes) of blob

func IsBlobURL added in v0.1.5

func IsBlobURL(raw string) bool

IsBlobURL performs a lightweight check whether the provided string is a blob endpoint URL.

func ListRecursiveStream added in v0.1.18

func ListRecursiveStream(ctx context.Context, ap AzurePath, scanConcurrency int, cb func(BlobMeta) error) error

func ListStream added in v0.1.16

func ListStream(ctx context.Context, ap AzurePath, cb func(BlobMeta) error) error

ListStream streams immediate children (non-recursive). If dir-like path provided, lists under it.

func MkContainer

func MkContainer(ctx context.Context, account, container string) error

MkContainer creates a new Azure Blob container

func PreAuthenticate added in v0.1.19

func PreAuthenticate(ctx context.Context, accounts ...string) error

PreAuthenticate eagerly authenticates to the given storage accounts sequentially. This ensures any interactive login popups happen one at a time before parallel workers start. It also pre-warms the blob client and UDC (User Delegation Credential) caches so that no credential acquisition happens during copy.

func RegisterAccountRole added in v0.1.19

func RegisterAccountRole(account, role string)

RegisterAccountRole tags the given storage account with a role ("SRC" or "DST"). When role-prefixed Azure identity environment variables are set (e.g. SRC_AZURE_TENANT_ID, DST_AZURE_CLIENT_ID, etc.), accounts tagged with the matching role will use those credentials instead of AzureCLI or interactive browser login. This makes authentication machine-friendly for CI/CD and multi-tenant environments. Changing the role invalidates cached blob clients and delegation credentials.

func SetHTTPTransport added in v0.1.21

func SetHTTPTransport(rt http.RoundTripper)

SetHTTPTransport installs a shared HTTP RoundTripper that will be used by every Azure SDK client constructed in this package. The RoundTripper is wrapped in an *http.Client so it satisfies policy.Transporter. Passing nil clears any previously configured transport.

This must be called before any SDK client is constructed; already-created clients keep their existing transport.

func SummarizeRecursive added in v0.1.26

func SummarizeRecursive(ctx context.Context, ap AzurePath, scanConcurrency int, onProgress func(count, size int64)) (int64, int64, error)

SummarizeRecursive counts blobs and bytes under ap. When the root contains multiple virtual directories, each directory is scanned independently so Azure continuation-token chains can advance in parallel.

func Touch added in v0.1.4

func Touch(ctx context.Context, ap AzurePath) error

Touch ensures the blob exists by creating an empty object when missing.

func Upload

func Upload(ctx context.Context, ap AzurePath, data []byte) error

Upload writes blob (overwrite)

func UploadFile added in v0.1.22

func UploadFile(ctx context.Context, ap AzurePath, file *os.File, concurrency int, onProgress func(int64)) error

UploadFile uploads a local file to a block blob using parallel ranged reads and StageBlock requests, mirroring azcopy's chunked upload for higher single-file throughput. concurrency is the initial parallelism (and floor); an adaptive controller probes higher concurrency while throughput keeps improving, up to uploadHardConcurrencyCap (overridable via BBB_AZBLOB_UPLOAD_CONCURRENCY_MAX). The optional onProgress callback receives the cumulative number of bytes staged.

If staging is rejected because stale uncommitted blocks poison the destination, the blob is cleared and the upload is retried once.

func UploadStream added in v0.1.8

func UploadStream(ctx context.Context, ap AzurePath, reader io.Reader, concurrency int) error

UploadStream writes blob content from a reader (overwrite).

Types

type AzurePath

type AzurePath struct {
	Account   string
	Container string
	Blob      string // may be empty or end with '/' for virtual directory
}

AzurePath represents an az:// path (account/container/blob)

func Parse

func Parse(raw string) (AzurePath, error)

Parse parses az://account/container[/blob] or https://account.blob.* URLs.

func (AzurePath) Child

func (p AzurePath) Child(rel string) AzurePath

func (AzurePath) IsDirLike

func (p AzurePath) IsDirLike() bool

func (AzurePath) String

func (p AzurePath) String() string

func (AzurePath) WithDir

func (p AzurePath) WithDir() AzurePath

type BlobMeta

type BlobMeta struct {
	Name string
	Size int64
}

BlobMeta minimal metadata for listing

func List

func List(ctx context.Context, ap AzurePath) ([]BlobMeta, error)

List lists immediate children (non-recursive). If dir-like path provided, lists under it.

func ListContainers

func ListContainers(ctx context.Context, account string) ([]BlobMeta, error)

ListContainers lists all containers in the account

func ListRecursive

func ListRecursive(ctx context.Context, ap AzurePath) ([]BlobMeta, error)

ListRecursive retrieves all blobs under path (treats path as prefix root)

type CopyProgress added in v0.1.17

type CopyProgress func(copied, total int64)

CopyProgress is called during server-side copy with the number of bytes copied so far and the total size in bytes.

It may be invoked concurrently from multiple StageBlockFromURL goroutines, so implementations must be goroutine-safe. The copied value passed to a single CopyProgress is already clamped to be monotonically non-decreasing, even across an internal InvalidBlobOrBlock self-heal retry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL