pageblob package - github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/pageblob - Go Packages (original) (raw)
ExamplePageBlobClient shows how to manipulate a page blob with PageBlobClient. A page blob is a collection of 512-byte pages optimized for random read and write operations. The maximum size for a page blob is 8 TB.
//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" "crypto/rand" "fmt" "log" "os"
"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/blob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/pageblob"
)
func handleError(err error) { if err != nil { log.Fatal(err.Error()) } }
// ExamplePageBlobClient shows how to manipulate a page blob with PageBlobClient. // A page blob is a collection of 512-byte pages optimized for random read and write operations. // The maximum size for a page blob is 8 TB. func main() { accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME") if !ok { panic("AZURE_STORAGE_ACCOUNT_NAME could not be found") } blobName := "test_page_blob.vhd" blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/testcontainer/%s", accountName, blobName)
cred, err := azidentity.NewDefaultAzureCredential(nil)
handleError(err)
pageBlobClient, err := pageblob.NewClient(blobURL, cred, nil)
handleError(err)
_, err = pageBlobClient.Create(context.TODO(), pageblob.PageBytes*4, nil)
handleError(err)
// Upload 5 pages to the page blob
for i := 0; i < 5; i++ {
count := int64(1024)
page := make([]byte, 2*pageblob.PageBytes)
_, err := rand.Read(page)
if err != nil {
return
}
_, err = pageBlobClient.UploadPages(context.Background(), streaming.NopCloser(bytes.NewReader(page)),
blob.HTTPRange{Offset: int64(i) * count, Count: count}, nil)
handleError(err)
}
pager := pageBlobClient.NewGetPageRangesPager(&pageblob.GetPageRangesOptions{
Range: blob.HTTPRange{
Count: int64(10 * pageblob.PageBytes),
},
})
for pager.More() {
resp, err := pager.NextPage(context.TODO())
if err != nil {
log.Fatal(err)
}
for _, pr := range resp.PageList.PageRange {
fmt.Printf("Start=%d, End=%d\n", pr.Start, pr.End)
}
}
get, err := pageBlobClient.DownloadStream(context.TODO(), nil)
handleError(err)
blobData := &bytes.Buffer{}
reader := get.Body
_, err = blobData.ReadFrom(reader)
if err != nil {
return
}
err = reader.Close()
if err != nil {
return
}
fmt.Println(blobData.String())
}
Output:
- func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error)
- func NewClientFromConnectionString(connectionString, containerName, blobName string, options *ClientOptions) (*Client, error)
- func NewClientWithNoCredential(blobURL string, options *ClientOptions) (*Client, error)
- func NewClientWithSharedKeyCredential(blobURL string, cred *blob.SharedKeyCredential, options *ClientOptions) (*Client, error)
- func (pb *Client) AbortCopyFromURL(ctx context.Context, copyID string, o *blob.AbortCopyFromURLOptions) (blob.AbortCopyFromURLResponse, error)
- func (pb *Client) BlobClient() *blob.Client
- func (pb *Client) ClearPages(ctx context.Context, rnge blob.HTTPRange, options *ClearPagesOptions) (ClearPagesResponse, error)
- func (pb *Client) CopyFromURL(ctx context.Context, copySource string, o *blob.CopyFromURLOptions) (blob.CopyFromURLResponse, error)
- func (pb *Client) Create(ctx context.Context, size int64, o *CreateOptions) (CreateResponse, error)
- func (pb *Client) CreateSnapshot(ctx context.Context, o *blob.CreateSnapshotOptions) (blob.CreateSnapshotResponse, error)
- func (pb *Client) Delete(ctx context.Context, o *blob.DeleteOptions) (blob.DeleteResponse, error)
- func (pb *Client) DeleteImmutabilityPolicy(ctx context.Context, options *blob.DeleteImmutabilityPolicyOptions) (blob.DeleteImmutabilityPolicyResponse, error)
- func (pb *Client) DownloadBuffer(ctx context.Context, buffer []byte, o *blob.DownloadBufferOptions) (int64, error)
- func (pb *Client) DownloadFile(ctx context.Context, file *os.File, o *blob.DownloadFileOptions) (int64, error)
- func (pb *Client) DownloadStream(ctx context.Context, o *blob.DownloadStreamOptions) (blob.DownloadStreamResponse, error)
- func (pb *Client) GetAccountInfo(ctx context.Context, o *blob.GetAccountInfoOptions) (blob.GetAccountInfoResponse, error)
- func (pb *Client) GetProperties(ctx context.Context, o *blob.GetPropertiesOptions) (blob.GetPropertiesResponse, error)
- func (pb *Client) GetSASURL(permissions sas.BlobPermissions, expiry time.Time, o *blob.GetSASURLOptions) (string, error)
- func (pb *Client) GetTags(ctx context.Context, o *blob.GetTagsOptions) (blob.GetTagsResponse, error)
- func (pb *Client) NewGetPageRangesDiffPager(o *GetPageRangesDiffOptions) *runtime.Pager[GetPageRangesDiffResponse]
- func (pb *Client) NewGetPageRangesPager(o *GetPageRangesOptions) *runtime.Pager[GetPageRangesResponse]
- func (pb *Client) Resize(ctx context.Context, size int64, options *ResizeOptions) (ResizeResponse, error)
- func (pb *Client) SetHTTPHeaders(ctx context.Context, httpHeaders blob.HTTPHeaders, ...) (blob.SetHTTPHeadersResponse, error)
- func (pb *Client) SetImmutabilityPolicy(ctx context.Context, expiryTime time.Time, ...) (blob.SetImmutabilityPolicyResponse, error)
- func (pb *Client) SetLegalHold(ctx context.Context, legalHold bool, options *blob.SetLegalHoldOptions) (blob.SetLegalHoldResponse, error)
- func (pb *Client) SetMetadata(ctx context.Context, metadata map[string]*string, o *blob.SetMetadataOptions) (blob.SetMetadataResponse, error)
- func (pb *Client) SetTags(ctx context.Context, tags map[string]string, o *blob.SetTagsOptions) (blob.SetTagsResponse, error)
- func (pb *Client) SetTier(ctx context.Context, tier blob.AccessTier, o *blob.SetTierOptions) (blob.SetTierResponse, error)
- func (pb *Client) StartCopyFromURL(ctx context.Context, copySource string, o *blob.StartCopyFromURLOptions) (blob.StartCopyFromURLResponse, error)
- func (pb *Client) StartCopyIncremental(ctx context.Context, copySource string, prevSnapshot string, ...) (CopyIncrementalResponse, error)
- func (pb *Client) URL() string
- func (pb *Client) Undelete(ctx context.Context, o *blob.UndeleteOptions) (blob.UndeleteResponse, error)
- func (pb *Client) UpdateSequenceNumber(ctx context.Context, options *UpdateSequenceNumberOptions) (UpdateSequenceNumberResponse, error)
- func (pb *Client) UploadPages(ctx context.Context, body io.ReadSeekCloser, contentRange blob.HTTPRange, ...) (UploadPagesResponse, error)
- func (pb *Client) UploadPagesFromURL(ctx context.Context, source string, sourceOffset, destOffset, count int64, ...) (UploadPagesFromURLResponse, error)
- func (pb *Client) WithSnapshot(snapshot string) (*Client, error)
- func (pb *Client) WithVersionID(versionID string) (*Client, error)
This section is empty.
This section is empty.
ClearPagesOptions contains the optional parameters for the Client.ClearPages operation
ClearPagesResponse contains the response from method Client.ClearPages.
ClearRange defines a range of pages.
Client represents a client to an Azure Storage page blob;
NewClient creates an instance of Client with the specified values.
- blobURL - the URL of the blob e.g. https://.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(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(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://.blob.core.windows.net/container/blob.txt?
- options - client options; pass nil to accept the default values
NewClientWithSharedKeyCredential creates an instance of Client with the specified values.
- blobURL - the URL of the blob e.g. https://.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
BlobClient returns the embedded blob client for this AppendBlob client.
DownloadBuffer downloads an Azure blob to a buffer with parallel.
DownloadFile downloads an Azure blob to a local file. The file would be truncated if the size doesn't match.
GetSASURL is a convenience method for generating a SAS token for the currently pointed at Page blob. It can only be used if the credential supplied during creation was a SharedKeyCredential.
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 tier-ing see https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers.
URL returns the URL endpoint used by the Client object.
UpdateSequenceNumber sets the page blob's sequence number.
UploadPages writes 1 or more pages to the page blob. The start offset and the stream size must be a multiple of 512 bytes. 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/put-page.
UploadPagesFromURL copies 1 or more pages from a source URL to the page blob. The sourceOffset specifies the start offset of source data to copy from. The destOffset specifies the start offset of data in page blob will be written to. The count must be a multiple of 512 bytes. For more information, see https://docs.microsoft.com/rest/api/storageservices/put-page-from-url.
WithSnapshot creates a new PageBlobURL object identical to the source but with the specified snapshot timestamp. Pass "" to remove the snapshot returning a URL to the base blob.
WithVersionID creates a new PageBlobURL object identical to the source but with the specified snapshot timestamp. Pass "" to remove the version returning a URL to the base blob.
ClientOptions contains the optional parameters when creating a Client.
CopyIncrementalOptions contains the optional parameters for the Client.StartCopyIncremental method.
CopyIncrementalResponse contains the response from method Client.StartCopyIncremental.
CopyStatusType defines values for CopyStatusType
func PossibleCopyStatusTypeValues() []CopyStatusType
PossibleCopyStatusTypeValues returns the possible values for the CopyStatusType const type.
CreateOptions contains the optional parameters for the Client.Create method.
CreateResponse contains the response from method Client.Create.
GetPageRangesDiffOptions contains the optional parameters for the Client.NewGetPageRangesDiffPager method.
GetPageRangesDiffResponse contains the response from method Client.NewGetPageRangesDiffPager.
GetPageRangesOptions contains the optional parameters for the Client.NewGetPageRangesPager method.
GetPageRangesResponse contains the response from method Client.NewGetPageRangesPager.
PageList - the list of pages.
PageRange defines a range of pages.
PremiumPageBlobAccessTier defines values for Premium PageBlob's AccessTier.
func PossiblePremiumPageBlobAccessTierValues() []PremiumPageBlobAccessTier
PossiblePremiumPageBlobAccessTierValues returns the possible values for the PremiumPageBlobAccessTier const type.
ResizeOptions contains the optional parameters for the Client.Resize method.
ResizeResponse contains the response from method Client.Resize.
SequenceNumberAccessConditions contains a group of parameters for the Client.UploadPages method.
SequenceNumberActionType defines values for SequenceNumberActionType.
func PossibleSequenceNumberActionTypeValues() []SequenceNumberActionType
PossibleSequenceNumberActionTypeValues returns the possible values for the SequenceNumberActionType const type.
UpdateSequenceNumberOptions contains the optional parameters for the Client.UpdateSequenceNumber method.
UpdateSequenceNumberResponse contains the response from method Client.UpdateSequenceNumber.
UploadPagesFromURLOptions contains the optional parameters for the Client.UploadPagesFromURL method.
UploadPagesFromURLResponse contains the response from method Client.UploadPagesFromURL.
UploadPagesOptions contains the optional parameters for the Client.UploadPages method.
UploadPagesResponse contains the response from method Client.UploadPages.