package appendblob
import "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/appendblob"
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).
Code:play
//go:build go1.18 // +build go1.18 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. 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()) } } // 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). 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()) }
Index ¶
- type AppendBlockFromURLOptions
- type AppendBlockFromURLResponse
- type AppendBlockOptions
- type AppendBlockResponse
- type AppendPositionAccessConditions
- type Client
- func NewClient(blobURL string, cred azcore.TokenCredential, o *ClientOptions) (*Client, error)
- func NewClientFromConnectionString(connectionString, containerName, blobName string, o *ClientOptions) (*Client, error)
- func NewClientWithNoCredential(blobURL string, o *ClientOptions) (*Client, error)
- func NewClientWithSharedKeyCredential(blobURL string, cred *blob.SharedKeyCredential, o *ClientOptions) (*Client, error)
- func (ab *Client) AbortCopyFromURL(ctx context.Context, copyID string, o *blob.AbortCopyFromURLOptions) (blob.AbortCopyFromURLResponse, error)
- func (ab *Client) AppendBlock(ctx context.Context, body io.ReadSeekCloser, o *AppendBlockOptions) (AppendBlockResponse, error)
- func (ab *Client) AppendBlockFromURL(ctx context.Context, source string, o *AppendBlockFromURLOptions) (AppendBlockFromURLResponse, error)
- func (ab *Client) BlobClient() *blob.Client
- func (ab *Client) CopyFromURL(ctx context.Context, copySource string, o *blob.CopyFromURLOptions) (blob.CopyFromURLResponse, error)
- func (ab *Client) Create(ctx context.Context, o *CreateOptions) (CreateResponse, error)
- func (ab *Client) CreateSnapshot(ctx context.Context, o *blob.CreateSnapshotOptions) (blob.CreateSnapshotResponse, error)
- func (ab *Client) Delete(ctx context.Context, o *blob.DeleteOptions) (blob.DeleteResponse, error)
- func (ab *Client) DownloadBuffer(ctx context.Context, buffer []byte, o *blob.DownloadBufferOptions) (int64, error)
- func (ab *Client) DownloadFile(ctx context.Context, file *os.File, o *blob.DownloadFileOptions) (int64, error)
- func (ab *Client) DownloadStream(ctx context.Context, o *blob.DownloadStreamOptions) (blob.DownloadStreamResponse, error)
- func (ab *Client) GetProperties(ctx context.Context, o *blob.GetPropertiesOptions) (blob.GetPropertiesResponse, error)
- func (ab *Client) GetTags(ctx context.Context, o *blob.GetTagsOptions) (blob.GetTagsResponse, error)
- func (ab *Client) Seal(ctx context.Context, o *SealOptions) (SealResponse, error)
- func (ab *Client) SetHTTPHeaders(ctx context.Context, HTTPHeaders blob.HTTPHeaders, o *blob.SetHTTPHeadersOptions) (blob.SetHTTPHeadersResponse, error)
- func (ab *Client) SetMetadata(ctx context.Context, metadata map[string]string, o *blob.SetMetadataOptions) (blob.SetMetadataResponse, error)
- func (ab *Client) SetTags(ctx context.Context, tags map[string]string, o *blob.SetTagsOptions) (blob.SetTagsResponse, error)
- func (ab *Client) SetTier(ctx context.Context, tier blob.AccessTier, o *blob.SetTierOptions) (blob.SetTierResponse, error)
- func (ab *Client) StartCopyFromURL(ctx context.Context, copySource string, o *blob.StartCopyFromURLOptions) (blob.StartCopyFromURLResponse, error)
- func (ab *Client) URL() string
- func (ab *Client) Undelete(ctx context.Context, o *blob.UndeleteOptions) (blob.UndeleteResponse, error)
- func (ab *Client) WithSnapshot(snapshot string) (*Client, error)
- func (ab *Client) WithVersionID(versionID string) (*Client, error)
- type ClientOptions
- type CreateOptions
- type CreateResponse
- type SealOptions
- type SealResponse
Examples ¶
Types ¶
type AppendBlockFromURLOptions ¶
type AppendBlockFromURLOptions struct { // Specify the md5 calculated for the range of bytes that must be read from the copy source. SourceContentMD5 []byte // Specify the crc64 calculated for the range of bytes that must be read from the copy source. SourceContentCRC64 []byte // Specify the transactional md5 for the body, to be validated by the service. TransactionalContentMD5 []byte 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 { // Specify the transactional crc64 for the body, to be validated by the service. TransactionalContentCRC64 []byte // Specify the transactional md5 for the body, to be validated by the service. TransactionalContentMD5 []byte 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 ¶
type Client base.CompositeClient[generated.BlobClient, generated.AppendBlobClient]
Client represents a client to an Azure Storage append blob;
func NewClient ¶
func NewClient(blobURL string, cred azcore.TokenCredential, o *ClientOptions) (*Client, error)
NewClient creates an AppendBlobClient with the specified URL, Azure AD credential, and options.
func NewClientFromConnectionString ¶
func NewClientFromConnectionString(connectionString, containerName, blobName string, o *ClientOptions) (*Client, error)
NewClientFromConnectionString creates Client from a connection String
func NewClientWithNoCredential ¶
func NewClientWithNoCredential(blobURL string, o *ClientOptions) (*Client, error)
NewClientWithNoCredential creates an AppendBlobClient with the specified URL and options.
func NewClientWithSharedKeyCredential ¶
func NewClientWithSharedKeyCredential(blobURL string, cred *blob.SharedKeyCredential, o *ClientOptions) (*Client, error)
NewClientWithSharedKeyCredential creates an AppendBlobClient with the specified URL, shared key, and options.
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 ¶
func (ab *Client) AppendBlock(ctx context.Context, body io.ReadSeekCloser, o *AppendBlockOptions) (AppendBlockResponse, error)
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 ¶
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 synchronously copies the data at the source URL to a block blob, with sizes up to 256 MB. For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob-from-url.
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 ¶
func (ab *Client) CreateSnapshot(ctx context.Context, o *blob.CreateSnapshotOptions) (blob.CreateSnapshotResponse, error)
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 ¶
func (ab *Client) Delete(ctx context.Context, o *blob.DeleteOptions) (blob.DeleteResponse, error)
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) 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 ¶
func (ab *Client) DownloadStream(ctx context.Context, o *blob.DownloadStreamOptions) (blob.DownloadStreamResponse, error)
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) GetProperties ¶
func (ab *Client) GetProperties(ctx context.Context, o *blob.GetPropertiesOptions) (blob.GetPropertiesResponse, error)
GetProperties returns the blob's properties. For more information, see https://docs.microsoft.com/rest/api/storageservices/get-blob-properties.
func (*Client) GetTags ¶
func (ab *Client) GetTags(ctx context.Context, o *blob.GetTagsOptions) (blob.GetTagsResponse, error)
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) 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) 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 ¶
func (ab *Client) SetTier(ctx context.Context, tier blob.AccessTier, o *blob.SetTierOptions) (blob.SetTierResponse, error)
SetTier operation sets the tier on a blob. The operation is allowed on a page blob in a premium storage account and on a block blob in a blob storage account (locally redundant storage only). A premium page blob's tier determines the allowed size, IOPS, and bandwidth of the blob. A block blob's tier determines Hot/Cool/Archive storage type. This operation does not update the blob's ETag. For detailed information about block blob level tiering see https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers.
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 ¶
URL returns the URL endpoint used by the Client object.
func (*Client) Undelete ¶
func (ab *Client) Undelete(ctx context.Context, o *blob.UndeleteOptions) (blob.UndeleteResponse, error)
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 ¶
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 ¶
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 struct { azcore.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 ¶
type CreateResponse = generated.AppendBlobClientCreateResponse
CreateResponse contains the response from method Client.Create.
type SealOptions ¶
type SealOptions struct { AccessConditions *blob.AccessConditions AppendPositionAccessConditions *AppendPositionAccessConditions }
SealOptions provides set of configurations for SealAppendBlob operation
type SealResponse ¶
type SealResponse = generated.AppendBlobClientSealResponse
SealResponse contains the response from method Client.Seal.
Source Files ¶
client.go models.go responses.go
- Version
- v0.5.0
- Published
- Sep 29, 2022
- Platform
- windows/amd64
- Imports
- 11 packages
- Last checked
- 3 hours ago –
Tools for package owners.