azurestore

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 24 Imported by: 3

Documentation

Index

Constants

View Source
const (
	InfoBlobSuffix        string = ".info"
	MaxBlockBlobSize      int64  = blockblob.MaxBlocks * blockblob.MaxStageBlockBytes
	MaxBlockBlobChunkSize int64  = blockblob.MaxStageBlockBytes
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AzBlob

type AzBlob interface {
	// Delete the blob
	Delete(ctx context.Context) error
	// Upload the blob
	Upload(ctx context.Context, body io.ReadSeeker) error
	// StageSentinelBlock stages a marker block so that a freshly created upload
	// always has at least one uncommitted block (see GetOffset).
	StageSentinelBlock(ctx context.Context) error
	// Download returns a readcloser to download the contents of the blob
	Download(ctx context.Context) (io.ReadCloser, error)
	// Get the offset of the blob and its indexes
	GetOffset(ctx context.Context) (int64, error)
	// Commit the uploaded blocks to the BlockBlob
	Commit(ctx context.Context) error
}

type AzConfig

type AzConfig struct {
	AccountName         string
	AccountKey          string
	BlobAccessTier      string
	ContainerName       string
	ContainerAccessType string
	Endpoint            string
}

type AzService

type AzService interface {
	NewBlob(ctx context.Context, name string) (AzBlob, error)
}

func NewAzureService

func NewAzureService(config *AzConfig) (AzService, error)

New Azure service for communication to Azure BlockBlob Storage API

type AzUpload

type AzUpload struct {
	ID          string
	InfoBlob    AzBlob
	BlockBlob   AzBlob
	InfoHandler *handler.FileInfo
	// contains filtered or unexported fields
}

func (*AzUpload) DeclareLength

func (upload *AzUpload) DeclareLength(ctx context.Context, length int64) error

func (*AzUpload) FinishUpload

func (upload *AzUpload) FinishUpload(ctx context.Context) error

Finish the file upload and commit the block list

func (*AzUpload) GetInfo

func (upload *AzUpload) GetInfo(ctx context.Context) (handler.FileInfo, error)

func (*AzUpload) GetReader

func (upload *AzUpload) GetReader(ctx context.Context) (io.ReadCloser, error)

Get the uploaded file from the Azure storage

func (*AzUpload) Terminate

func (upload *AzUpload) Terminate(ctx context.Context) error

func (*AzUpload) WriteChunk

func (upload *AzUpload) WriteChunk(ctx context.Context, offset int64, src io.Reader) (int64, error)

type AzureStore

type AzureStore struct {
	Service      AzService
	ObjectPrefix string
	Container    string

	// TemporaryDirectory is the path where AzureStore will create temporary files
	// on disk during the upload. An empty string ("", the default value) will
	// cause AzureStore to use the operating system's default temporary directory.
	TemporaryDirectory string
}

func New

func New(service AzService) *AzureStore

func (AzureStore) AsLengthDeclarableUpload

func (store AzureStore) AsLengthDeclarableUpload(upload handler.Upload) handler.LengthDeclarableUpload

func (AzureStore) AsTerminatableUpload

func (store AzureStore) AsTerminatableUpload(upload handler.Upload) handler.TerminatableUpload

func (AzureStore) GetUpload

func (store AzureStore) GetUpload(ctx context.Context, id string) (handler.Upload, error)

func (AzureStore) NewUpload

func (store AzureStore) NewUpload(ctx context.Context, info handler.FileInfo) (handler.Upload, error)

func (AzureStore) UseIn

func (store AzureStore) UseIn(composer *handler.StoreComposer)

UseIn sets this store as the core data store in the passed composer and adds all possible extension to it.

type BlockBlob

type BlockBlob struct {
	BlobClient     *blockblob.Client
	Indexes        []int
	BlobAccessTier *blob.AccessTier
}

func (*BlockBlob) Commit

func (blockBlob *BlockBlob) Commit(ctx context.Context) error

After all the blocks have been uploaded, we commit the unstaged blocks by sending a Block List

func (*BlockBlob) Delete

func (blockBlob *BlockBlob) Delete(ctx context.Context) error

Delete the blockBlob from Azure Blob Storage

func (*BlockBlob) Download

func (blockBlob *BlockBlob) Download(ctx context.Context) (io.ReadCloser, error)

Download the blockBlob from Azure Blob Storage

func (*BlockBlob) GetOffset

func (blockBlob *BlockBlob) GetOffset(ctx context.Context) (int64, error)

func (*BlockBlob) StageSentinelBlock added in v2.10.0

func (blockBlob *BlockBlob) StageSentinelBlock(ctx context.Context) error

StageSentinelBlock stages a marker block so that a freshly created upload always has at least one uncommitted block. This lets GetOffset reliably tell a finished upload (no uncommitted blocks) apart from a newly created one, even when blob versioning leaves committed blocks behind on the blob (see #1349).

The marker is identified by a dedicated, reserved block ID, so it is never added to the committed block list (Commit only commits blockBlob.Indexes) and is dropped by Azure once the real blocks are committed. GetOffset skips it explicitly.

Azure rejects staging a zero-length block (it returns InvalidHeaderValue for Content-Length: 0, see #1358), so the marker carries a single byte.

func (*BlockBlob) Upload

func (blockBlob *BlockBlob) Upload(ctx context.Context, body io.ReadSeeker) error

Upload a block to Azure Blob Storage and add it to the indexes to be after upload is finished

type InfoBlob

type InfoBlob struct {
	BlobClient *blockblob.Client
}

func (*InfoBlob) Commit

func (infoBlob *InfoBlob) Commit(ctx context.Context) error

infoBlob does not have uncommited blocks, so just return nil

func (*InfoBlob) Delete

func (infoBlob *InfoBlob) Delete(ctx context.Context) error

Delete the infoBlob from Azure Blob Storage

func (*InfoBlob) Download

func (infoBlob *InfoBlob) Download(ctx context.Context) (io.ReadCloser, error)

Download the infoBlob from Azure Blob Storage

func (*InfoBlob) GetOffset

func (infoBlob *InfoBlob) GetOffset(ctx context.Context) (int64, error)

infoBlob does not utilise offset, so just return 0, nil

func (*InfoBlob) StageSentinelBlock added in v2.10.0

func (infoBlob *InfoBlob) StageSentinelBlock(ctx context.Context) error

infoBlob does not use a sentinel block, so this is a no-op.

func (*InfoBlob) Upload

func (infoBlob *InfoBlob) Upload(ctx context.Context, body io.ReadSeeker) error

Upload the infoBlob to Azure Blob Storage Because the info file is presumed to be smaller than azblob.BlockBlobMaxUploadBlobBytes (256MiB), we can upload it all in one go New uploaded data will create a new, or overwrite the existing block blob

Jump to

Keyboard shortcuts

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