appendblob

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 14 Imported by: 5

Documentation

Overview

Example (Appendblob_Client)

ExampleAppendBlobClient shows how to append data (in blocks) to an append blob. An append blob can have a maximum of 50,000 blocks; each block can have a maximum of 100MB. The maximum size of an append blob is slightly more than 4.75 TB (100 MB X 50,000 blocks).

package main

import (
	"bytes"
	"context"
	"fmt"
	"log"
	"os"
	"strings"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/appendblob"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_NAME could not be found")
	}
	blobName := "test_append_blob.txt"
	blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/testcontainer/%s", accountName, blobName)

	cred, err := azidentity.NewDefaultAzureCredential(nil)
	handleError(err)

	appendBlobClient, err := appendblob.NewClient(blobURL, cred, nil)
	handleError(err)

	_, err = appendBlobClient.Create(context.TODO(), nil)
	handleError(err)

	for i := 0; i < 5; i++ { // Append 5 blocks to the append blob
		_, err := appendBlobClient.AppendBlock(context.TODO(), streaming.NopCloser(strings.NewReader(fmt.Sprintf("Appending block #%d\n", i))), nil)
		if err != nil {
			log.Fatal(err)
		}
	}

	// Download the entire append blob's contents and read into a bytes.Buffer.
	get, err := appendBlobClient.DownloadStream(context.TODO(), nil)
	handleError(err)
	b := bytes.Buffer{}
	reader := get.Body
	_, err = b.ReadFrom(reader)
	if err != nil {
		return
	}
	err = reader.Close()
	if err != nil {
		return
	}
	fmt.Println(b.String())
}
Output:

Example (Appendblob_Seal)
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/appendblob"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_NAME could not be found")
	}
	blobName := "test_append_blob_seal.txt"
	blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/testcontainer/%s", accountName, blobName)

	cred, err := azidentity.NewDefaultAzureCredential(nil)
	handleError(err)

	appendBlobClient, err := appendblob.NewClient(blobURL, cred, nil)
	handleError(err)

	_, err = appendBlobClient.Seal(context.Background(), nil)
	handleError(err)
}
Output:

Example (Appendblob_SetExpiry)

This example shows how to set an expiry time on an existing blob This operation is only allowed on Hierarchical Namespace enabled accounts.

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"

	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/appendblob"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_NAME could not be found")
	}
	blobName := "test_append_blob_set_expiry.txt"
	blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/testcontainer/%s", accountName, blobName)

	cred, err := azidentity.NewDefaultAzureCredential(nil)
	handleError(err)

	appendBlobClient, err := appendblob.NewClient(blobURL, cred, nil)
	handleError(err)

	// set expiry on append blob to an absolute time
	expiryTimeAbsolute := time.Now().Add(8 * time.Hour)
	_, err = appendBlobClient.SetExpiry(context.TODO(), appendblob.ExpiryTypeAbsolute(expiryTimeAbsolute), nil)
	handleError(err)

	// validate set expiry operation
	resp, err := appendBlobClient.GetProperties(context.TODO(), nil)
	handleError(err)
	if resp.ExpiresOn == nil || expiryTimeAbsolute.UTC().Format(http.TimeFormat) != (*resp.ExpiresOn).UTC().Format(http.TimeFormat) {
		return
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendBlockFromURLOptions

type AppendBlockFromURLOptions struct {
	// Only Bearer type is supported. Credentials should be a valid OAuth access token to copy source.
	CopySourceAuthorization *string

	// SourceContentValidation contains the validation mechanism used on the range of bytes read from the source.
	SourceContentValidation blob.SourceContentValidationType

	AppendPositionAccessConditions *AppendPositionAccessConditions

	CPKInfo *blob.CPKInfo

	CPKScopeInfo *blob.CPKScopeInfo

	SourceModifiedAccessConditions *blob.SourceModifiedAccessConditions

	AccessConditions *blob.AccessConditions

	// Range specifies a range of bytes.  The default value is all bytes.
	Range blob.HTTPRange
}

AppendBlockFromURLOptions contains the optional parameters for the Client.AppendBlockFromURL method.

type AppendBlockFromURLResponse

type AppendBlockFromURLResponse = generated.AppendBlobClientAppendBlockFromURLResponse

AppendBlockFromURLResponse contains the response from method Client.AppendBlockFromURL.

type AppendBlockOptions

type AppendBlockOptions struct {
	// TransactionalValidation specifies the transfer validation type to use.
	// The default is nil (no transfer validation).
	TransactionalValidation blob.TransferValidationType

	AppendPositionAccessConditions *AppendPositionAccessConditions

	CPKInfo *blob.CPKInfo

	CPKScopeInfo *blob.CPKScopeInfo

	AccessConditions *blob.AccessConditions
}

AppendBlockOptions contains the optional parameters for the Client.AppendBlock method.

type AppendBlockResponse

type AppendBlockResponse = generated.AppendBlobClientAppendBlockResponse

AppendBlockResponse contains the response from method Client.AppendBlock.

type AppendPositionAccessConditions

type AppendPositionAccessConditions = generated.AppendPositionAccessConditions

AppendPositionAccessConditions contains a group of parameters for the Client.AppendBlock method.

type Client

Client represents a client to an Azure Storage append blob;

func NewClient

func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error)

NewClient creates an instance of Client with the specified values.

  • blobURL - the URL of the blob e.g. https://<account>.blob.core.windows.net/container/blob.txt
  • cred - an Azure AD credential, typically obtained via the azidentity module
  • options - client options; pass nil to accept the default values

func NewClientFromConnectionString

func NewClientFromConnectionString(connectionString, containerName, blobName string, options *ClientOptions) (*Client, error)

NewClientFromConnectionString creates an instance of Client with the specified values.

  • connectionString - a connection string for the desired storage account
  • containerName - the name of the container within the storage account
  • blobName - the name of the blob within the container
  • options - client options; pass nil to accept the default values

func NewClientWithNoCredential

func NewClientWithNoCredential(blobURL string, options *ClientOptions) (*Client, error)

NewClientWithNoCredential creates an instance of Client with the specified values. This is used to anonymously access a blob or with a shared access signature (SAS) token.

  • blobURL - the URL of the blob e.g. https://<account>.blob.core.windows.net/container/blob.txt?<sas token>
  • options - client options; pass nil to accept the default values

func NewClientWithSharedKeyCredential

func NewClientWithSharedKeyCredential(blobURL string, cred *blob.SharedKeyCredential, options *ClientOptions) (*Client, error)

NewClientWithSharedKeyCredential creates an instance of Client with the specified values.

  • blobURL - the URL of the blob e.g. https://<account>.blob.core.windows.net/container/blob.txt
  • cred - a SharedKeyCredential created with the matching blob's storage account and access key
  • options - client options; pass nil to accept the default values

func (*Client) AbortCopyFromURL

func (ab *Client) AbortCopyFromURL(ctx context.Context, copyID string, o *blob.AbortCopyFromURLOptions) (blob.AbortCopyFromURLResponse, error)

AbortCopyFromURL stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. For more information, see https://docs.microsoft.com/rest/api/storageservices/abort-copy-blob.

func (*Client) AppendBlock

AppendBlock writes a stream to a new block of data to the end of the existing append blob. This method panics if the stream is not at position 0. Note that the http client closes the body stream after the request is sent to the service. For more information, see https://docs.microsoft.com/rest/api/storageservices/append-block.

func (*Client) AppendBlockFromURL

func (ab *Client) AppendBlockFromURL(ctx context.Context, source string, o *AppendBlockFromURLOptions) (AppendBlockFromURLResponse, error)

AppendBlockFromURL copies a new block of data from source URL to the end of the existing append blob. For more information, see https://docs.microsoft.com/rest/api/storageservices/append-block-from-url.

func (*Client) BlobClient

func (ab *Client) BlobClient() *blob.Client

BlobClient returns the embedded blob client for this AppendBlob client.

func (*Client) CopyFromURL

func (ab *Client) CopyFromURL(ctx context.Context, copySource string, o *blob.CopyFromURLOptions) (blob.CopyFromURLResponse, error)

CopyFromURL Deprecated: CopyFromURL works only with block blob

func (*Client) Create

func (ab *Client) Create(ctx context.Context, o *CreateOptions) (CreateResponse, error)

Create creates a 0-size append blob. Call AppendBlock to append data to an append blob. For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.

func (*Client) CreateSnapshot

CreateSnapshot creates a read-only snapshot of a blob. For more information, see https://docs.microsoft.com/rest/api/storageservices/snapshot-blob.

func (*Client) Delete

Delete marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. Note that deleting a blob also deletes all its snapshots. For more information, see https://docs.microsoft.com/rest/api/storageservices/delete-blob.

func (*Client) DeleteImmutabilityPolicy added in v0.6.0

DeleteImmutabilityPolicy operation enables users to delete the immutability policy on a blob. https://learn.microsoft.com/en-us/azure/storage/blobs/immutable-storage-overview

func (*Client) DownloadBuffer

func (ab *Client) DownloadBuffer(ctx context.Context, buffer []byte, o *blob.DownloadBufferOptions) (int64, error)

DownloadBuffer downloads an Azure blob to a buffer with parallel.

func (*Client) DownloadFile

func (ab *Client) DownloadFile(ctx context.Context, file *os.File, o *blob.DownloadFileOptions) (int64, error)

DownloadFile downloads an Azure blob to a local file. The file would be truncated if the size doesn't match.

func (*Client) DownloadStream

DownloadStream reads a range of bytes from a blob. The response also includes the blob's properties and metadata. For more information, see https://docs.microsoft.com/rest/api/storageservices/get-blob.

func (*Client) GetAccountInfo added in v1.1.0

GetAccountInfo provides account level information For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-account-information?tabs=shared-access-signatures.

func (*Client) GetProperties

GetProperties returns the blob's properties. For more information, see https://docs.microsoft.com/rest/api/storageservices/get-blob-properties.

func (*Client) GetSASURL added in v1.2.1

func (ab *Client) GetSASURL(permissions sas.BlobPermissions, expiry time.Time, o *blob.GetSASURLOptions) (string, error)

GetSASURL is a convenience method for generating a SAS token for the currently pointed at append blob. It can only be used if the credential supplied during creation was a SharedKeyCredential.

func (*Client) GetTags

GetTags operation enables users to get tags on a blob or specific blob version, or snapshot. https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-tags

func (*Client) Seal

func (ab *Client) Seal(ctx context.Context, o *SealOptions) (SealResponse, error)

Seal - The purpose of Append Blob Seal is to allow users and applications to seal append blobs, marking them as read only. https://docs.microsoft.com/en-us/rest/api/storageservices/append-blob-seal

func (*Client) SetExpiry added in v0.6.0

func (ab *Client) SetExpiry(ctx context.Context, expiryType ExpiryType, o *SetExpiryOptions) (SetExpiryResponse, error)

SetExpiry operation sets an expiry time on an existing blob. This operation is only allowed on Hierarchical Namespace enabled accounts. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-blob-expiry

func (*Client) SetHTTPHeaders

func (ab *Client) SetHTTPHeaders(ctx context.Context, HTTPHeaders blob.HTTPHeaders, o *blob.SetHTTPHeadersOptions) (blob.SetHTTPHeadersResponse, error)

SetHTTPHeaders changes a blob's HTTP headers. For more information, see https://docs.microsoft.com/rest/api/storageservices/set-blob-properties.

func (*Client) SetImmutabilityPolicy added in v0.6.0

func (ab *Client) SetImmutabilityPolicy(ctx context.Context, expiryTime time.Time, options *blob.SetImmutabilityPolicyOptions) (blob.SetImmutabilityPolicyResponse, error)

SetImmutabilityPolicy operation enables users to set the immutability policy on a blob. https://learn.microsoft.com/en-us/azure/storage/blobs/immutable-storage-overview

func (*Client) SetLegalHold added in v0.6.0

func (ab *Client) SetLegalHold(ctx context.Context, legalHold bool, options *blob.SetLegalHoldOptions) (blob.SetLegalHoldResponse, error)

SetLegalHold operation enables users to set legal hold on a blob. https://learn.microsoft.com/en-us/azure/storage/blobs/immutable-storage-overview

func (*Client) SetMetadata

func (ab *Client) SetMetadata(ctx context.Context, metadata map[string]*string, o *blob.SetMetadataOptions) (blob.SetMetadataResponse, error)

SetMetadata changes a blob's metadata. https://docs.microsoft.com/rest/api/storageservices/set-blob-metadata.

func (*Client) SetTags

func (ab *Client) SetTags(ctx context.Context, tags map[string]string, o *blob.SetTagsOptions) (blob.SetTagsResponse, error)

SetTags operation enables users to set tags on a blob or specific blob version, but not snapshot. Each call to this operation replaces all existing tags attached to the blob. To remove all tags from the blob, call this operation with no tags set. https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tags

func (*Client) SetTier

SetTier Deprecated: SetTier only works for page blob in premium storage account and block blob in blob storage account.

func (*Client) StartCopyFromURL

func (ab *Client) StartCopyFromURL(ctx context.Context, copySource string, o *blob.StartCopyFromURLOptions) (blob.StartCopyFromURLResponse, error)

StartCopyFromURL copies the data at the source URL to a blob. For more information, see https://docs.microsoft.com/rest/api/storageservices/copy-blob.

func (*Client) URL

func (ab *Client) URL() string

URL returns the URL endpoint used by the Client object.

func (*Client) Undelete

Undelete restores the contents and metadata of a soft-deleted blob and any associated soft-deleted snapshots. For more information, see https://docs.microsoft.com/rest/api/storageservices/undelete-blob.

func (*Client) WithSnapshot

func (ab *Client) WithSnapshot(snapshot string) (*Client, error)

WithSnapshot creates a new AppendBlobURL object identical to the source but with the specified snapshot timestamp. Pass "" to remove the snapshot returning a URL to the base blob.

func (*Client) WithVersionID

func (ab *Client) WithVersionID(versionID string) (*Client, error)

WithVersionID creates a new AppendBlobURL object identical to the source but with the specified version id. Pass "" to remove the versionID returning a URL to the base blob.

type ClientOptions

type ClientOptions base.ClientOptions

ClientOptions contains the optional parameters when creating a Client.

type CreateOptions

type CreateOptions struct {
	// Specifies the date time when the blobs immutability policy is set to expire.
	ImmutabilityPolicyExpiry *time.Time

	// Specifies the immutability policy mode to set on the blob.
	ImmutabilityPolicyMode *blob.ImmutabilityPolicySetting

	// Specified if a legal hold should be set on the blob.
	LegalHold *bool

	AccessConditions *blob.AccessConditions

	HTTPHeaders *blob.HTTPHeaders

	CPKInfo *blob.CPKInfo

	CPKScopeInfo *blob.CPKScopeInfo

	// Optional. Used to set blob tags in various blob operations.
	Tags map[string]string

	// Optional. Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the
	// operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs
	// are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source
	// blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers.
	// See Naming and Referencing Containers, Blobs, and Metadata for more information.
	Metadata map[string]*string
}

CreateOptions provides set of configurations for Create Append Blob operation

type CreateResponse

CreateResponse contains the response from method Client.Create.

type ExpiryType added in v0.6.0

type ExpiryType = exported.ExpiryType

ExpiryType defines values for ExpiryType

type ExpiryTypeAbsolute added in v0.6.0

type ExpiryTypeAbsolute = exported.ExpiryTypeAbsolute

ExpiryTypeAbsolute defines the absolute time for the blob expiry

type ExpiryTypeNever added in v0.6.0

type ExpiryTypeNever = exported.ExpiryTypeNever

ExpiryTypeNever defines that the blob will be set to never expire

type ExpiryTypeRelativeToCreation added in v0.6.0

type ExpiryTypeRelativeToCreation = exported.ExpiryTypeRelativeToCreation

ExpiryTypeRelativeToCreation defines the duration relative to creation for the blob expiry

type ExpiryTypeRelativeToNow added in v0.6.0

type ExpiryTypeRelativeToNow = exported.ExpiryTypeRelativeToNow

ExpiryTypeRelativeToNow defines the duration relative to now for the blob expiry

type SealOptions

type SealOptions struct {
	AccessConditions               *blob.AccessConditions
	AppendPositionAccessConditions *AppendPositionAccessConditions
}

SealOptions provides set of configurations for SealAppendBlob operation

type SealResponse

SealResponse contains the response from method Client.Seal.

type SetExpiryOptions added in v0.6.0

type SetExpiryOptions = exported.SetExpiryOptions

SetExpiryOptions contains the optional parameters for the Client.SetExpiry method.

type SetExpiryResponse added in v0.6.0

type SetExpiryResponse = generated.BlobClientSetExpiryResponse

SetExpiryResponse contains the response from method Client.SetExpiry.

Jump to

Keyboard shortcuts

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