From 92453a24a3dd563f637b1d666f841438d15260ba Mon Sep 17 00:00:00 2001 From: Benoit Perrot Date: Thu, 21 Oct 2021 17:21:04 +0200 Subject: [PATCH 1/2] azblob.downloadBlobToWriterAt: initialDownloadResponse: remove as unused --- sdk/storage/azblob/highlevel.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/sdk/storage/azblob/highlevel.go b/sdk/storage/azblob/highlevel.go index bdf89cb6c2e0..219fc8f28537 100644 --- a/sdk/storage/azblob/highlevel.go +++ b/sdk/storage/azblob/highlevel.go @@ -231,23 +231,19 @@ func (o *HighLevelDownloadFromBlobOptions) getDownloadBlobOptions(offSet, count } // downloadBlobToWriterAt downloads an Azure blob to a buffer with parallel. -func (b BlobClient) downloadBlobToWriterAt(ctx context.Context, offset int64, count int64, writer io.WriterAt, o HighLevelDownloadFromBlobOptions, initialDownloadResponse *DownloadResponse) error { +func (b BlobClient) downloadBlobToWriterAt(ctx context.Context, offset int64, count int64, writer io.WriterAt, o HighLevelDownloadFromBlobOptions) error { if o.BlockSize == 0 { o.BlockSize = BlobDefaultDownloadBlockSize } if count == CountToEnd { // If size not specified, calculate it - if initialDownloadResponse != nil { - count = *initialDownloadResponse.ContentLength - offset // if we have the length, use it - } else { - // If we don't have the length at all, get it - downloadBlobOptions := o.getDownloadBlobOptions(0, CountToEnd, nil) - dr, err := b.Download(ctx, downloadBlobOptions) - if err != nil { - return err - } - count = *dr.ContentLength - offset + // If we don't have the length at all, get it + downloadBlobOptions := o.getDownloadBlobOptions(0, CountToEnd, nil) + dr, err := b.Download(ctx, downloadBlobOptions) + if err != nil { + return err } + count = *dr.ContentLength - offset } if count <= 0 { @@ -302,7 +298,7 @@ func (b BlobClient) downloadBlobToWriterAt(ctx context.Context, offset int64, co // DownloadBlobToBuffer downloads an Azure blob to a buffer with parallel. // Offset and count are optional, pass 0 for both to download the entire blob. func (b BlobClient) DownloadBlobToBuffer(ctx context.Context, offset int64, count int64, _bytes []byte, o HighLevelDownloadFromBlobOptions) error { - return b.downloadBlobToWriterAt(ctx, offset, count, newBytesWriter(_bytes), o, nil) + return b.downloadBlobToWriterAt(ctx, offset, count, newBytesWriter(_bytes), o) } // DownloadBlobToFile downloads an Azure blob to a local file. @@ -336,7 +332,7 @@ func (b BlobClient) DownloadBlobToFile(ctx context.Context, offset int64, count } if size > 0 { - return b.downloadBlobToWriterAt(ctx, offset, size, file, o, nil) + return b.downloadBlobToWriterAt(ctx, offset, size, file, o) } else { // if the blob's size is 0, there is no need in downloading it return nil } From fbc87c1ee475569e6f2aa7f14bd731627f5556d7 Mon Sep 17 00:00:00 2001 From: Benoit Perrot Date: Thu, 21 Oct 2021 18:33:38 +0200 Subject: [PATCH 2/2] azblob.DownloadBlobToWriterAt: make public --- sdk/storage/azblob/highlevel.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/storage/azblob/highlevel.go b/sdk/storage/azblob/highlevel.go index 219fc8f28537..892f2f6fc174 100644 --- a/sdk/storage/azblob/highlevel.go +++ b/sdk/storage/azblob/highlevel.go @@ -230,8 +230,9 @@ func (o *HighLevelDownloadFromBlobOptions) getDownloadBlobOptions(offSet, count } } -// downloadBlobToWriterAt downloads an Azure blob to a buffer with parallel. -func (b BlobClient) downloadBlobToWriterAt(ctx context.Context, offset int64, count int64, writer io.WriterAt, o HighLevelDownloadFromBlobOptions) error { +// DownloadBlobToWriterAt downloads an Azure blob to a WriterAt with parallel. +// Offset and count are optional, pass 0 for both to download the entire blob. +func (b BlobClient) DownloadBlobToWriterAt(ctx context.Context, offset int64, count int64, writer io.WriterAt, o HighLevelDownloadFromBlobOptions) error { if o.BlockSize == 0 { o.BlockSize = BlobDefaultDownloadBlockSize } @@ -298,7 +299,7 @@ func (b BlobClient) downloadBlobToWriterAt(ctx context.Context, offset int64, co // DownloadBlobToBuffer downloads an Azure blob to a buffer with parallel. // Offset and count are optional, pass 0 for both to download the entire blob. func (b BlobClient) DownloadBlobToBuffer(ctx context.Context, offset int64, count int64, _bytes []byte, o HighLevelDownloadFromBlobOptions) error { - return b.downloadBlobToWriterAt(ctx, offset, count, newBytesWriter(_bytes), o) + return b.DownloadBlobToWriterAt(ctx, offset, count, newBytesWriter(_bytes), o) } // DownloadBlobToFile downloads an Azure blob to a local file. @@ -332,7 +333,7 @@ func (b BlobClient) DownloadBlobToFile(ctx context.Context, offset int64, count } if size > 0 { - return b.downloadBlobToWriterAt(ctx, offset, size, file, o) + return b.DownloadBlobToWriterAt(ctx, offset, size, file, o) } else { // if the blob's size is 0, there is no need in downloading it return nil }