|
Packit |
63bb0d |
package azblob
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
import (
|
|
Packit |
63bb0d |
"context"
|
|
Packit |
63bb0d |
"io"
|
|
Packit |
63bb0d |
"net/url"
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
"github.com/Azure/azure-pipeline-go/pipeline"
|
|
Packit |
63bb0d |
)
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
const (
|
|
Packit |
63bb0d |
// BlockBlobMaxUploadBlobBytes indicates the maximum number of bytes that can be sent in a call to Upload.
|
|
Packit |
63bb0d |
BlockBlobMaxUploadBlobBytes = 256 * 1024 * 1024 // 256MB
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// BlockBlobMaxStageBlockBytes indicates the maximum number of bytes that can be sent in a call to StageBlock.
|
|
Packit Service |
3a6627 |
BlockBlobMaxStageBlockBytes = 4000 * 1024 * 1024 // 4000MiB
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// BlockBlobMaxBlocks indicates the maximum number of blocks allowed in a block blob.
|
|
Packit |
63bb0d |
BlockBlobMaxBlocks = 50000
|
|
Packit |
63bb0d |
)
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// BlockBlobURL defines a set of operations applicable to block blobs.
|
|
Packit |
63bb0d |
type BlockBlobURL struct {
|
|
Packit |
63bb0d |
BlobURL
|
|
Packit |
63bb0d |
bbClient blockBlobClient
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// NewBlockBlobURL creates a BlockBlobURL object using the specified URL and request policy pipeline.
|
|
Packit |
63bb0d |
func NewBlockBlobURL(url url.URL, p pipeline.Pipeline) BlockBlobURL {
|
|
Packit |
63bb0d |
blobClient := newBlobClient(url, p)
|
|
Packit |
63bb0d |
bbClient := newBlockBlobClient(url, p)
|
|
Packit |
63bb0d |
return BlockBlobURL{BlobURL: BlobURL{blobClient: blobClient}, bbClient: bbClient}
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// WithPipeline creates a new BlockBlobURL object identical to the source but with the specific request policy pipeline.
|
|
Packit |
63bb0d |
func (bb BlockBlobURL) WithPipeline(p pipeline.Pipeline) BlockBlobURL {
|
|
Packit |
63bb0d |
return NewBlockBlobURL(bb.blobClient.URL(), p)
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// WithSnapshot creates a new BlockBlobURL object identical to the source but with the specified snapshot timestamp.
|
|
Packit |
63bb0d |
// Pass "" to remove the snapshot returning a URL to the base blob.
|
|
Packit |
63bb0d |
func (bb BlockBlobURL) WithSnapshot(snapshot string) BlockBlobURL {
|
|
Packit |
63bb0d |
p := NewBlobURLParts(bb.URL())
|
|
Packit |
63bb0d |
p.Snapshot = snapshot
|
|
Packit |
63bb0d |
return NewBlockBlobURL(p.URL(), bb.blobClient.Pipeline())
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit Service |
3a6627 |
// WithVersionID creates a new BlockBlobURRL object identical to the source but with the specified version id.
|
|
Packit Service |
3a6627 |
// Pass "" to remove the snapshot returning a URL to the base blob.
|
|
Packit Service |
3a6627 |
func (bb BlockBlobURL) WithVersionID(versionId string) BlockBlobURL {
|
|
Packit Service |
3a6627 |
p := NewBlobURLParts(bb.URL())
|
|
Packit Service |
3a6627 |
p.VersionID = versionId
|
|
Packit Service |
3a6627 |
return NewBlockBlobURL(p.URL(), bb.blobClient.Pipeline())
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
func (bb BlockBlobURL) GetAccountInfo(ctx context.Context) (*BlobGetAccountInfoResponse, error) {
|
|
Packit Service |
3a6627 |
return bb.blobClient.GetAccountInfo(ctx)
|
|
Packit Service |
3a6627 |
}
|
|
Packit Service |
3a6627 |
|
|
Packit |
63bb0d |
// Upload creates a new block blob or overwrites an existing block blob.
|
|
Packit |
63bb0d |
// Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not
|
|
Packit |
63bb0d |
// supported with Upload; the content of the existing blob is overwritten with the new content. To
|
|
Packit |
63bb0d |
// perform a partial update of a block blob, use StageBlock and CommitBlockList.
|
|
Packit |
63bb0d |
// This method panics if the stream is not at position 0.
|
|
Packit |
63bb0d |
// Note that the http client closes the body stream after the request is sent to the service.
|
|
Packit |
63bb0d |
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-blob.
|
|
Packit Service |
3a6627 |
func (bb BlockBlobURL) Upload(ctx context.Context, body io.ReadSeeker, h BlobHTTPHeaders, metadata Metadata, ac BlobAccessConditions, tier AccessTierType, blobTagsMap BlobTagsMap, cpk ClientProvidedKeyOptions) (*BlockBlobUploadResponse, error) {
|
|
Packit |
63bb0d |
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.ModifiedAccessConditions.pointers()
|
|
Packit |
63bb0d |
count, err := validateSeekableStreamAt0AndGetCount(body)
|
|
Packit Service |
3a6627 |
blobTagsString := SerializeBlobTagsHeader(blobTagsMap)
|
|
Packit |
63bb0d |
if err != nil {
|
|
Packit |
63bb0d |
return nil, err
|
|
Packit |
63bb0d |
}
|
|
Packit Service |
3a6627 |
return bb.bbClient.Upload(ctx, body, count, nil, nil,
|
|
Packit |
63bb0d |
&h.ContentType, &h.ContentEncoding, &h.ContentLanguage, h.ContentMD5,
|
|
Packit Service |
3a6627 |
&h.CacheControl, metadata, ac.LeaseAccessConditions.pointers(), &h.ContentDisposition,
|
|
Packit Service |
3a6627 |
cpk.EncryptionKey, cpk.EncryptionKeySha256, cpk.EncryptionAlgorithm, // CPK-V
|
|
Packit Service |
3a6627 |
cpk.EncryptionScope, // CPK-N
|
|
Packit Service |
3a6627 |
tier, ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag,
|
|
Packit Service |
3a6627 |
nil, // Blob ifTags
|
|
Packit Service |
3a6627 |
nil,
|
|
Packit Service |
3a6627 |
blobTagsString, // Blob tags
|
|
Packit Service |
3a6627 |
)
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// StageBlock uploads the specified block to the block blob's "staging area" to be later committed by a call to CommitBlockList.
|
|
Packit |
63bb0d |
// Note that the http client closes the body stream after the request is sent to the service.
|
|
Packit |
63bb0d |
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-block.
|
|
Packit Service |
3a6627 |
func (bb BlockBlobURL) StageBlock(ctx context.Context, base64BlockID string, body io.ReadSeeker, ac LeaseAccessConditions, transactionalMD5 []byte, cpk ClientProvidedKeyOptions) (*BlockBlobStageBlockResponse, error) {
|
|
Packit |
63bb0d |
count, err := validateSeekableStreamAt0AndGetCount(body)
|
|
Packit |
63bb0d |
if err != nil {
|
|
Packit |
63bb0d |
return nil, err
|
|
Packit |
63bb0d |
}
|
|
Packit Service |
3a6627 |
return bb.bbClient.StageBlock(ctx, base64BlockID, count, body, transactionalMD5, nil, nil, ac.pointers(),
|
|
Packit Service |
3a6627 |
cpk.EncryptionKey, cpk.EncryptionKeySha256, cpk.EncryptionAlgorithm, // CPK-V
|
|
Packit Service |
3a6627 |
cpk.EncryptionScope, // CPK-N
|
|
Packit Service |
3a6627 |
nil)
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// StageBlockFromURL copies the specified block from a source URL to the block blob's "staging area" to be later committed by a call to CommitBlockList.
|
|
Packit |
63bb0d |
// If count is CountToEnd (0), then data is read from specified offset to the end.
|
|
Packit |
63bb0d |
// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-from-url.
|
|
Packit Service |
3a6627 |
func (bb BlockBlobURL) StageBlockFromURL(ctx context.Context, base64BlockID string, sourceURL url.URL, offset int64, count int64, destinationAccessConditions LeaseAccessConditions, sourceAccessConditions ModifiedAccessConditions, cpk ClientProvidedKeyOptions) (*BlockBlobStageBlockFromURLResponse, error) {
|
|
Packit |
63bb0d |
sourceIfModifiedSince, sourceIfUnmodifiedSince, sourceIfMatchETag, sourceIfNoneMatchETag := sourceAccessConditions.pointers()
|
|
Packit Service |
3a6627 |
return bb.bbClient.StageBlockFromURL(ctx, base64BlockID, 0, sourceURL.String(), httpRange{offset: offset, count: count}.pointers(), nil, nil, nil,
|
|
Packit Service |
3a6627 |
cpk.EncryptionKey, cpk.EncryptionKeySha256, cpk.EncryptionAlgorithm, // CPK
|
|
Packit Service |
3a6627 |
cpk.EncryptionScope, // CPK-N
|
|
Packit Service |
3a6627 |
destinationAccessConditions.pointers(), sourceIfModifiedSince, sourceIfUnmodifiedSince, sourceIfMatchETag, sourceIfNoneMatchETag, nil)
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// CommitBlockList writes a blob by specifying the list of block IDs that make up the blob.
|
|
Packit |
63bb0d |
// In order to be written as part of a blob, a block must have been successfully written
|
|
Packit |
63bb0d |
// to the server in a prior PutBlock operation. You can call PutBlockList to update a blob
|
|
Packit |
63bb0d |
// by uploading only those blocks that have changed, then committing the new and existing
|
|
Packit |
63bb0d |
// blocks together. Any blocks not specified in the block list and permanently deleted.
|
|
Packit |
63bb0d |
// For more information, see https://docs.microsoft.com/rest/api/storageservices/put-block-list.
|
|
Packit Service |
3a6627 |
func (bb BlockBlobURL) CommitBlockList(ctx context.Context, base64BlockIDs []string, h BlobHTTPHeaders, metadata Metadata, ac BlobAccessConditions, tier AccessTierType, blobTagsMap BlobTagsMap, cpk ClientProvidedKeyOptions) (*BlockBlobCommitBlockListResponse, error) {
|
|
Packit |
63bb0d |
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.ModifiedAccessConditions.pointers()
|
|
Packit Service |
3a6627 |
blobTagsString := SerializeBlobTagsHeader(blobTagsMap)
|
|
Packit |
63bb0d |
return bb.bbClient.CommitBlockList(ctx, BlockLookupList{Latest: base64BlockIDs}, nil,
|
|
Packit Service |
3a6627 |
&h.CacheControl, &h.ContentType, &h.ContentEncoding, &h.ContentLanguage, h.ContentMD5, nil, nil,
|
|
Packit |
63bb0d |
metadata, ac.LeaseAccessConditions.pointers(), &h.ContentDisposition,
|
|
Packit Service |
3a6627 |
cpk.EncryptionKey, cpk.EncryptionKeySha256, cpk.EncryptionAlgorithm, // CPK
|
|
Packit Service |
3a6627 |
cpk.EncryptionScope, // CPK-N
|
|
Packit Service |
3a6627 |
tier,
|
|
Packit Service |
3a6627 |
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag,
|
|
Packit Service |
3a6627 |
nil, // Blob ifTags
|
|
Packit Service |
3a6627 |
nil,
|
|
Packit Service |
3a6627 |
blobTagsString, // Blob tags
|
|
Packit Service |
3a6627 |
)
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// GetBlockList returns the list of blocks that have been uploaded as part of a block blob using the specified block list filter.
|
|
Packit |
63bb0d |
// For more information, see https://docs.microsoft.com/rest/api/storageservices/get-block-list.
|
|
Packit |
63bb0d |
func (bb BlockBlobURL) GetBlockList(ctx context.Context, listType BlockListType, ac LeaseAccessConditions) (*BlockList, error) {
|
|
Packit Service |
3a6627 |
return bb.bbClient.GetBlockList(ctx, listType, nil, nil, ac.pointers(),
|
|
Packit Service |
3a6627 |
nil, // Blob ifTags
|
|
Packit Service |
3a6627 |
nil)
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit Service |
3a6627 |
// CopyFromURL synchronously copies the data at the source URL to a block blob, with sizes up to 256 MB.
|
|
Packit Service |
3a6627 |
// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob-from-url.
|
|
Packit Service |
3a6627 |
func (bb BlockBlobURL) CopyFromURL(ctx context.Context, source url.URL, metadata Metadata, srcac ModifiedAccessConditions, dstac BlobAccessConditions, srcContentMD5 []byte, tier AccessTierType, blobTagsMap BlobTagsMap) (*BlobCopyFromURLResponse, error) {
|
|
Packit Service |
3a6627 |
|
|
Packit Service |
3a6627 |
srcIfModifiedSince, srcIfUnmodifiedSince, srcIfMatchETag, srcIfNoneMatchETag := srcac.pointers()
|
|
Packit Service |
3a6627 |
dstIfModifiedSince, dstIfUnmodifiedSince, dstIfMatchETag, dstIfNoneMatchETag := dstac.ModifiedAccessConditions.pointers()
|
|
Packit Service |
3a6627 |
dstLeaseID := dstac.LeaseAccessConditions.pointers()
|
|
Packit Service |
3a6627 |
blobTagsString := SerializeBlobTagsHeader(blobTagsMap)
|
|
Packit Service |
3a6627 |
return bb.blobClient.CopyFromURL(ctx, source.String(), nil, metadata, tier,
|
|
Packit Service |
3a6627 |
srcIfModifiedSince, srcIfUnmodifiedSince,
|
|
Packit Service |
3a6627 |
srcIfMatchETag, srcIfNoneMatchETag,
|
|
Packit Service |
3a6627 |
dstIfModifiedSince, dstIfUnmodifiedSince,
|
|
Packit Service |
3a6627 |
dstIfMatchETag, dstIfNoneMatchETag,
|
|
Packit Service |
3a6627 |
nil, // Blob ifTags
|
|
Packit Service |
3a6627 |
dstLeaseID, nil, srcContentMD5,
|
|
Packit Service |
3a6627 |
blobTagsString, // Blob tags
|
|
Packit Service |
3a6627 |
nil, // seal Blob
|
|
Packit Service |
3a6627 |
)
|
|
Packit |
63bb0d |
}
|