azurestore

package
v2.0.0-staffbase-rc16 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InfoBlobSuffix        string = ".info"
	MaxBlockBlobSize      int64  = azblob.BlockBlobMaxBlocks * azblob.BlockBlobMaxStageBlockBytes
	MaxBlockBlobChunkSize int64  = azblob.BlockBlobMaxStageBlockBytes
)

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
	// 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
}

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
}

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 {
	Blob       *azblob.BlockBlobURL
	AccessTier azblob.AccessTierType
	Indexes    []int
}

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) 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 {
	Blob *azblob.BlockBlobURL
}

func (*InfoBlob) Commit

func (infoBlob *InfoBlob) Commit(_ 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(_ context.Context) (int64, error)

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

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