diff --git a/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md b/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md index 3fe9b88537cb6..786a5ff1c0da6 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md @@ -3,6 +3,7 @@ ## 12.20.0-beta.2 (Unreleased) ### Features Added +- Deprecated Read()/ReadAsync() in favor of ReadStreaming()/ReadStreamingAsync() and ReadContent()/ReadContentAsync() for DataLake #45418 ### Breaking Changes diff --git a/sdk/storage/Azure.Storage.Files.DataLake/README.md b/sdk/storage/Azure.Storage.Files.DataLake/README.md index 249a5c0dced06..e5136a042ff56 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/README.md +++ b/sdk/storage/Azure.Storage.Files.DataLake/README.md @@ -156,6 +156,18 @@ file.Flush(SampleFileContent.Length); Response fileContents = file.Read(); ``` +### Reading Streaming Data from a DataLake File +```C# Snippet:SampleSnippetDataLakeFileClient_ReadStreaming +Response fileContents = file.ReadStreaming(); +Stream readStream = fileContents.Value.Content; +``` + +### Reading Content Data from a DataLake File +```C# Snippet:SampleSnippetDataLakeFileClient_ReadContent +Response fileContents = file.ReadContent(); +BinaryData readData = fileContents.Value.Content; +``` + ### Listing/Traversing through a DataLake Filesystem ```C# Snippet:SampleSnippetDataLakeFileClient_List foreach (PathItem pathItem in filesystem.GetPaths()) diff --git a/sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.net6.0.cs b/sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.net6.0.cs index efd9e87cdaeff..84ffe47a07714 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.net6.0.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.net6.0.cs @@ -170,16 +170,34 @@ public DataLakeFileClient(System.Uri fileUri, Azure.Storage.StorageSharedKeyCred public virtual System.Threading.Tasks.Task OpenWriteAsync(bool overwrite, Azure.Storage.Files.DataLake.Models.DataLakeFileOpenWriteOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response Query(string querySqlExpression, Azure.Storage.Files.DataLake.Models.DataLakeQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> QueryAsync(string querySqlExpression, Azure.Storage.Files.DataLake.Models.DataLakeQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response Read() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response Read(Azure.HttpRange range, Azure.Storage.Files.DataLake.Models.DataLakeRequestConditions conditions, bool rangeGetContentHash, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response Read(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response Read(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual System.Threading.Tasks.Task> ReadAsync() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual System.Threading.Tasks.Task> ReadAsync(Azure.HttpRange range, Azure.Storage.Files.DataLake.Models.DataLakeRequestConditions conditions, bool rangeGetContentHash, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual System.Threading.Tasks.Task> ReadAsync(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual System.Threading.Tasks.Task> ReadAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ReadContent() { throw null; } + public virtual Azure.Response ReadContent(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ReadContent(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ReadContentAsync() { throw null; } + public virtual System.Threading.Tasks.Task> ReadContentAsync(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ReadContentAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ReadStreaming() { throw null; } + public virtual Azure.Response ReadStreaming(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ReadStreaming(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ReadStreamingAsync() { throw null; } + public virtual System.Threading.Tasks.Task> ReadStreamingAsync(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ReadStreamingAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response ReadTo(System.IO.Stream destination, Azure.Storage.Files.DataLake.Models.DataLakeFileReadToOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response ReadTo(System.IO.Stream destination, Azure.Storage.Files.DataLake.Models.DataLakeRequestConditions conditions, Azure.Storage.StorageTransferOptions transferOptions, System.Threading.CancellationToken cancellationToken) { throw null; } @@ -644,6 +662,19 @@ public DataLakeFileReadOptions() { } public Azure.HttpRange Range { get { throw null; } set { } } public Azure.Storage.DownloadTransferValidationOptions TransferValidation { get { throw null; } set { } } } + public partial class DataLakeFileReadResult + { + internal DataLakeFileReadResult() { } + public System.BinaryData Content { get { throw null; } } + public Azure.Storage.Files.DataLake.Models.FileDownloadDetails Details { get { throw null; } } + } + public partial class DataLakeFileReadStreamingResult : System.IDisposable + { + internal DataLakeFileReadStreamingResult() { } + public System.IO.Stream Content { get { throw null; } } + public Azure.Storage.Files.DataLake.Models.FileDownloadDetails Details { get { throw null; } } + public void Dispose() { } + } public partial class DataLakeFileReadToOptions { public DataLakeFileReadToOptions() { } @@ -730,6 +761,8 @@ public DataLakeMetrics() { } } public static partial class DataLakeModelFactory { + public static Azure.Storage.Files.DataLake.Models.DataLakeFileReadResult DataLakeFileReadResult(System.BinaryData content, Azure.Storage.Files.DataLake.Models.FileDownloadDetails details) { throw null; } + public static Azure.Storage.Files.DataLake.Models.DataLakeFileReadStreamingResult DataLakeFileReadStreamingResult(System.IO.Stream content, Azure.Storage.Files.DataLake.Models.FileDownloadDetails details) { throw null; } public static Azure.Storage.Files.DataLake.Models.DataLakeQueryError DataLakeQueryError(string name = null, string description = null, bool isFatal = false, long position = (long)0) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Storage.Files.DataLake.Models.FileDownloadDetails FileDownloadDetails(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary metadata, string contentRange, Azure.ETag eTag, string contentEncoding, string cacheControl, string contentDisposition, string contentLanguage, System.DateTimeOffset copyCompletionTime, string copyStatusDescription, string copyId, string copyProgress, System.Uri copySource, Azure.Storage.Files.DataLake.Models.CopyStatus copyStatus, Azure.Storage.Files.DataLake.Models.DataLakeLeaseDuration leaseDuration, Azure.Storage.Files.DataLake.Models.DataLakeLeaseState leaseState, Azure.Storage.Files.DataLake.Models.DataLakeLeaseStatus leaseStatus, string acceptRanges, bool isServerEncrypted, string encryptionKeySha256, byte[] contentHash) { throw null; } @@ -738,6 +771,7 @@ public static partial class DataLakeModelFactory [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Storage.Files.DataLake.Models.FileDownloadDetails FileDownloadDetails(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary metadata, string contentRange, Azure.ETag eTag, string contentEncoding, string cacheControl, string contentDisposition, string contentLanguage, System.DateTimeOffset copyCompletionTime, string copyStatusDescription, string copyId, string copyProgress, System.Uri copySource, Azure.Storage.Files.DataLake.Models.CopyStatus copyStatus, Azure.Storage.Files.DataLake.Models.DataLakeLeaseDuration leaseDuration, Azure.Storage.Files.DataLake.Models.DataLakeLeaseState leaseState, Azure.Storage.Files.DataLake.Models.DataLakeLeaseStatus leaseStatus, string acceptRanges, bool isServerEncrypted, string encryptionKeySha256, byte[] contentHash, System.DateTimeOffset createdOn, string encryptionContext) { throw null; } public static Azure.Storage.Files.DataLake.Models.FileDownloadDetails FileDownloadDetails(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary metadata, string contentRange, Azure.ETag eTag, string contentEncoding, string cacheControl, string contentDisposition, string contentLanguage, System.DateTimeOffset copyCompletionTime, string copyStatusDescription, string copyId, string copyProgress, System.Uri copySource, Azure.Storage.Files.DataLake.Models.CopyStatus copyStatus, Azure.Storage.Files.DataLake.Models.DataLakeLeaseDuration leaseDuration, Azure.Storage.Files.DataLake.Models.DataLakeLeaseState leaseState, Azure.Storage.Files.DataLake.Models.DataLakeLeaseStatus leaseStatus, string acceptRanges, bool isServerEncrypted, string encryptionKeySha256, byte[] contentHash, System.DateTimeOffset createdOn, string encryptionContext, System.Collections.Generic.IList accessControlList) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Storage.Files.DataLake.Models.FileDownloadInfo FileDownloadInfo(long contentLength, System.IO.Stream content, byte[] contentHash, Azure.Storage.Files.DataLake.Models.FileDownloadDetails properties) { throw null; } public static Azure.Storage.Files.DataLake.Models.FileSystemInfo FileSystemInfo(Azure.ETag etag, System.DateTimeOffset lastModified) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.netstandard2.0.cs b/sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.netstandard2.0.cs index efd9e87cdaeff..84ffe47a07714 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.netstandard2.0.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/api/Azure.Storage.Files.DataLake.netstandard2.0.cs @@ -170,16 +170,34 @@ public DataLakeFileClient(System.Uri fileUri, Azure.Storage.StorageSharedKeyCred public virtual System.Threading.Tasks.Task OpenWriteAsync(bool overwrite, Azure.Storage.Files.DataLake.Models.DataLakeFileOpenWriteOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response Query(string querySqlExpression, Azure.Storage.Files.DataLake.Models.DataLakeQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> QueryAsync(string querySqlExpression, Azure.Storage.Files.DataLake.Models.DataLakeQueryOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response Read() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response Read(Azure.HttpRange range, Azure.Storage.Files.DataLake.Models.DataLakeRequestConditions conditions, bool rangeGetContentHash, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response Read(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response Read(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual System.Threading.Tasks.Task> ReadAsync() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual System.Threading.Tasks.Task> ReadAsync(Azure.HttpRange range, Azure.Storage.Files.DataLake.Models.DataLakeRequestConditions conditions, bool rangeGetContentHash, System.Threading.CancellationToken cancellationToken) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual System.Threading.Tasks.Task> ReadAsync(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual System.Threading.Tasks.Task> ReadAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ReadContent() { throw null; } + public virtual Azure.Response ReadContent(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ReadContent(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ReadContentAsync() { throw null; } + public virtual System.Threading.Tasks.Task> ReadContentAsync(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ReadContentAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ReadStreaming() { throw null; } + public virtual Azure.Response ReadStreaming(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ReadStreaming(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ReadStreamingAsync() { throw null; } + public virtual System.Threading.Tasks.Task> ReadStreamingAsync(Azure.Storage.Files.DataLake.Models.DataLakeFileReadOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ReadStreamingAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response ReadTo(System.IO.Stream destination, Azure.Storage.Files.DataLake.Models.DataLakeFileReadToOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public virtual Azure.Response ReadTo(System.IO.Stream destination, Azure.Storage.Files.DataLake.Models.DataLakeRequestConditions conditions, Azure.Storage.StorageTransferOptions transferOptions, System.Threading.CancellationToken cancellationToken) { throw null; } @@ -644,6 +662,19 @@ public DataLakeFileReadOptions() { } public Azure.HttpRange Range { get { throw null; } set { } } public Azure.Storage.DownloadTransferValidationOptions TransferValidation { get { throw null; } set { } } } + public partial class DataLakeFileReadResult + { + internal DataLakeFileReadResult() { } + public System.BinaryData Content { get { throw null; } } + public Azure.Storage.Files.DataLake.Models.FileDownloadDetails Details { get { throw null; } } + } + public partial class DataLakeFileReadStreamingResult : System.IDisposable + { + internal DataLakeFileReadStreamingResult() { } + public System.IO.Stream Content { get { throw null; } } + public Azure.Storage.Files.DataLake.Models.FileDownloadDetails Details { get { throw null; } } + public void Dispose() { } + } public partial class DataLakeFileReadToOptions { public DataLakeFileReadToOptions() { } @@ -730,6 +761,8 @@ public DataLakeMetrics() { } } public static partial class DataLakeModelFactory { + public static Azure.Storage.Files.DataLake.Models.DataLakeFileReadResult DataLakeFileReadResult(System.BinaryData content, Azure.Storage.Files.DataLake.Models.FileDownloadDetails details) { throw null; } + public static Azure.Storage.Files.DataLake.Models.DataLakeFileReadStreamingResult DataLakeFileReadStreamingResult(System.IO.Stream content, Azure.Storage.Files.DataLake.Models.FileDownloadDetails details) { throw null; } public static Azure.Storage.Files.DataLake.Models.DataLakeQueryError DataLakeQueryError(string name = null, string description = null, bool isFatal = false, long position = (long)0) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Storage.Files.DataLake.Models.FileDownloadDetails FileDownloadDetails(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary metadata, string contentRange, Azure.ETag eTag, string contentEncoding, string cacheControl, string contentDisposition, string contentLanguage, System.DateTimeOffset copyCompletionTime, string copyStatusDescription, string copyId, string copyProgress, System.Uri copySource, Azure.Storage.Files.DataLake.Models.CopyStatus copyStatus, Azure.Storage.Files.DataLake.Models.DataLakeLeaseDuration leaseDuration, Azure.Storage.Files.DataLake.Models.DataLakeLeaseState leaseState, Azure.Storage.Files.DataLake.Models.DataLakeLeaseStatus leaseStatus, string acceptRanges, bool isServerEncrypted, string encryptionKeySha256, byte[] contentHash) { throw null; } @@ -738,6 +771,7 @@ public static partial class DataLakeModelFactory [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Storage.Files.DataLake.Models.FileDownloadDetails FileDownloadDetails(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary metadata, string contentRange, Azure.ETag eTag, string contentEncoding, string cacheControl, string contentDisposition, string contentLanguage, System.DateTimeOffset copyCompletionTime, string copyStatusDescription, string copyId, string copyProgress, System.Uri copySource, Azure.Storage.Files.DataLake.Models.CopyStatus copyStatus, Azure.Storage.Files.DataLake.Models.DataLakeLeaseDuration leaseDuration, Azure.Storage.Files.DataLake.Models.DataLakeLeaseState leaseState, Azure.Storage.Files.DataLake.Models.DataLakeLeaseStatus leaseStatus, string acceptRanges, bool isServerEncrypted, string encryptionKeySha256, byte[] contentHash, System.DateTimeOffset createdOn, string encryptionContext) { throw null; } public static Azure.Storage.Files.DataLake.Models.FileDownloadDetails FileDownloadDetails(System.DateTimeOffset lastModified, System.Collections.Generic.IDictionary metadata, string contentRange, Azure.ETag eTag, string contentEncoding, string cacheControl, string contentDisposition, string contentLanguage, System.DateTimeOffset copyCompletionTime, string copyStatusDescription, string copyId, string copyProgress, System.Uri copySource, Azure.Storage.Files.DataLake.Models.CopyStatus copyStatus, Azure.Storage.Files.DataLake.Models.DataLakeLeaseDuration leaseDuration, Azure.Storage.Files.DataLake.Models.DataLakeLeaseState leaseState, Azure.Storage.Files.DataLake.Models.DataLakeLeaseStatus leaseStatus, string acceptRanges, bool isServerEncrypted, string encryptionKeySha256, byte[] contentHash, System.DateTimeOffset createdOn, string encryptionContext, System.Collections.Generic.IList accessControlList) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Storage.Files.DataLake.Models.FileDownloadInfo FileDownloadInfo(long contentLength, System.IO.Stream content, byte[] contentHash, Azure.Storage.Files.DataLake.Models.FileDownloadDetails properties) { throw null; } public static Azure.Storage.Files.DataLake.Models.FileSystemInfo FileSystemInfo(Azure.ETag etag, System.DateTimeOffset lastModified) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/sdk/storage/Azure.Storage.Files.DataLake/assets.json b/sdk/storage/Azure.Storage.Files.DataLake/assets.json index 442889d04be63..d3270d0cbc634 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/assets.json +++ b/sdk/storage/Azure.Storage.Files.DataLake/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/storage/Azure.Storage.Files.DataLake", - "Tag": "net/storage/Azure.Storage.Files.DataLake_186c14971d" + "Tag": "net/storage/Azure.Storage.Files.DataLake_43c4036919" } diff --git a/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample01a_HelloWorld.cs b/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample01a_HelloWorld.cs index 3f8cfdd32c7c5..f8369e587453a 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample01a_HelloWorld.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample01a_HelloWorld.cs @@ -325,6 +325,115 @@ public void Read() } } + /// + /// Download a DataLake File's streaming data to a file. + /// + [Test] + public void ReadStreaming() + { + // Create a temporary Lorem Ipsum file on disk that we can upload + string originalPath = CreateTempFile(SampleFileContent); + + // Get a temporary path on disk where we can download the file + string downloadPath = CreateTempPath(); + + // Make StorageSharedKeyCredential to pass to the serviceClient + string storageAccountName = StorageAccountName; + string storageAccountKey = StorageAccountKey; + Uri serviceUri = StorageAccountBlobUri; + StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); + + // Create DataLakeServiceClient using StorageSharedKeyCredentials + DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential); + + // Get a reference to a filesystem named "sample-filesystem-read" and then create it + DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient("sample-filesystem-read"); + filesystem.Create(); + try + { + // Get a reference to a file named "sample-file" in a filesystem + DataLakeFileClient file = filesystem.GetFileClient("sample-file"); + + // First upload something the DataLake file so we have something to download + file.Upload(File.OpenRead(originalPath)); + + // Download the DataLake file's contents and save it to a file + // The ReadStreamingAsync() API downloads a file in a single requests. + // For large files, it may be faster to call ReadTo() + #region Snippet:SampleSnippetDataLakeFileClient_ReadStreaming + Response fileContents = file.ReadStreaming(); + Stream readStream = fileContents.Value.Content; + #endregion Snippet:SampleSnippetDataLakeFileClient_ReadStreaming + using (FileStream stream = File.OpenWrite(downloadPath)) + { + readStream.CopyTo(stream); + } + + // Verify the contents + Assert.AreEqual(SampleFileContent, File.ReadAllText(downloadPath)); + } + finally + { + // Clean up after the test when we're finished + filesystem.Delete(); + } + } + + /// + /// Download a DataLake File's content data to a file. + /// + [Test] + public void ReadContent() + { + // Create a temporary Lorem Ipsum file on disk that we can upload + string originalPath = CreateTempFile(SampleFileContent); + + // Get a temporary path on disk where we can download the file + string downloadPath = CreateTempPath(); + + // Make StorageSharedKeyCredential to pass to the serviceClient + string storageAccountName = StorageAccountName; + string storageAccountKey = StorageAccountKey; + Uri serviceUri = StorageAccountBlobUri; + StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); + + // Create DataLakeServiceClient using StorageSharedKeyCredentials + DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential); + + // Get a reference to a filesystem named "sample-filesystem-read" and then create it + DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient("sample-filesystem-read"); + filesystem.Create(); + try + { + // Get a reference to a file named "sample-file" in a filesystem + DataLakeFileClient file = filesystem.GetFileClient("sample-file"); + + // First upload something the DataLake file so we have something to download + file.Upload(File.OpenRead(originalPath)); + + // Download the DataLake file's contents and save it to a file + // The ReadContentAsync() API downloads a file in a single requests. + // For large files, it may be faster to call ReadTo() + #region Snippet:SampleSnippetDataLakeFileClient_ReadContent + Response fileContents = file.ReadContent(); + BinaryData readData = fileContents.Value.Content; + #endregion Snippet:SampleSnippetDataLakeFileClient_ReadContent + byte[] data = readData.ToArray(); + using (FileStream stream = File.OpenWrite(downloadPath)) + { + stream.Write(data, 0, data.Length); + } + + // Verify the contents + Assert.AreEqual(SampleFileContent, File.ReadAllText(downloadPath)); + } + finally + { + // Clean up after the test when we're finished + filesystem.Delete(); + } + } + /// /// Download a DataLake File to a file. /// diff --git a/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample01b_HelloWorldAsync.cs b/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample01b_HelloWorldAsync.cs index c00d412854193..227cdfaf27a7b 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample01b_HelloWorldAsync.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample01b_HelloWorldAsync.cs @@ -327,6 +327,111 @@ public async Task ReadAsync() } } + /// + /// Download a DataLake File's streaming data to a file. + /// + [Test] + public async Task ReadStreamingAsync() + { + // Create a temporary Lorem Ipsum file on disk that we can upload + string originalPath = CreateTempFile(SampleFileContent); + + // Get a temporary path on disk where we can download the file + string downloadPath = CreateTempPath(); + + // Make StorageSharedKeyCredential to pass to the serviceClient + string storageAccountName = StorageAccountName; + string storageAccountKey = StorageAccountKey; + Uri serviceUri = StorageAccountBlobUri; + StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); + + // Create DataLakeServiceClient using StorageSharedKeyCredentials + DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential); + + // Get a reference to a filesystem named "sample-filesystem-readasync" and then create it + DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-read")); + await filesystem.CreateAsync(); + try + { + // Get a reference to a file named "sample-file" in a filesystem + DataLakeFileClient file = filesystem.GetFileClient(Randomize("sample-file")); + + // First upload something the DataLake file so we have something to download + await file.UploadAsync(File.OpenRead(originalPath)); + + // Download the DataLake file's contents and save it to a file + // The ReadStreamingAsync() API downloads a file in a single requests. + // For large files, it may be faster to call ReadToAsync() + Response fileContents = await file.ReadStreamingAsync(); + Stream readStream = fileContents.Value.Content; + using (FileStream stream = File.OpenWrite(downloadPath)) + { + readStream.CopyTo(stream); + } + + // Verify the contents + Assert.AreEqual(SampleFileContent, File.ReadAllText(downloadPath)); + } + finally + { + // Clean up after the test when we're finished + await filesystem.DeleteAsync(); + } + } + + /// + /// Download a DataLake File's content data to a file. + /// + [Test] + public async Task ReadContentAsync() + { + // Create a temporary Lorem Ipsum file on disk that we can upload + string originalPath = CreateTempFile(SampleFileContent); + + // Get a temporary path on disk where we can download the file + string downloadPath = CreateTempPath(); + + // Make StorageSharedKeyCredential to pass to the serviceClient + string storageAccountName = StorageAccountName; + string storageAccountKey = StorageAccountKey; + Uri serviceUri = StorageAccountBlobUri; + StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); + + // Create DataLakeServiceClient using StorageSharedKeyCredentials + DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential); + + // Get a reference to a filesystem named "sample-filesystem-readasync" and then create it + DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-read")); + await filesystem.CreateAsync(); + try + { + // Get a reference to a file named "sample-file" in a filesystem + DataLakeFileClient file = filesystem.GetFileClient(Randomize("sample-file")); + + // First upload something the DataLake file so we have something to download + await file.UploadAsync(File.OpenRead(originalPath)); + + // Download the DataLake file's contents and save it to a file + // The ReadContentAsync() API downloads a file in a single requests. + // For large files, it may be faster to call ReadToAsync() + Response fileContents = await file.ReadContentAsync(); + BinaryData readData = fileContents.Value.Content; + byte[] data = readData.ToArray(); + using (FileStream stream = File.OpenWrite(downloadPath)) + { + stream.Write(data, 0, data.Length); + } + + // Verify the contents + Assert.AreEqual(SampleFileContent, File.ReadAllText(downloadPath)); + } + finally + { + // Clean up after the test when we're finished + await filesystem.DeleteAsync(); + } + } + /// /// Download a DataLake File directly to file. /// diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeExtensions.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeExtensions.cs index 9d50525a1120c..77f5257c56923 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeExtensions.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeExtensions.cs @@ -99,6 +99,29 @@ internal static FileDownloadInfo ToFileDownloadInfo(this Response blobDownloadStreamingResultResponse) + { + blobDownloadStreamingResultResponse.GetRawResponse().Headers.TryGetValue(Constants.DataLake.EncryptionContextHeaderName, out string encryptionContext); + blobDownloadStreamingResultResponse.GetRawResponse().Headers.TryGetValue(Constants.DataLake.AclHeaderName, out string accessControlList); + DataLakeFileReadStreamingResult dataLakeFileReadStreamingResult = new DataLakeFileReadStreamingResult() + { + Content = blobDownloadStreamingResultResponse.Value.Content, + Details = blobDownloadStreamingResultResponse.Value.Details.ToFileDownloadDetails(encryptionContext, accessControlList) + }; + return dataLakeFileReadStreamingResult; + } + + internal static DataLakeFileReadResult ToDataLakeFileReadResult(this Response blobDownloadResult) + { + blobDownloadResult.GetRawResponse().Headers.TryGetValue(Constants.DataLake.EncryptionContextHeaderName, out string encryptionContext); + blobDownloadResult.GetRawResponse().Headers.TryGetValue(Constants.DataLake.AclHeaderName, out string accessControlList); + DataLakeFileReadResult dataLakeFileReadResult = new DataLakeFileReadResult() + { + Content = blobDownloadResult.Value.Content, + Details = blobDownloadResult.Value.Details.ToFileDownloadDetails(encryptionContext, accessControlList) + }; + return dataLakeFileReadResult; + } internal static PathProperties ToPathProperties(this Response blobPropertiesResponse) { diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs index 3d2bd710e25aa..ef00d2b9c4ac0 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs @@ -2827,6 +2827,8 @@ internal virtual async Task> FlushInternal( #endregion #region Read Data + + #region Deprecated /// /// The operation downloads a file from /// the service, including its metadata and properties. @@ -2844,6 +2846,7 @@ internal virtual async Task> FlushInternal( /// A will be thrown if /// a failure occurs. /// + [EditorBrowsable(EditorBrowsableState.Never)] public virtual Response Read() { DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(Read)}"); @@ -2886,6 +2889,7 @@ public virtual Response Read() /// A will be thrown if /// a failure occurs. /// + [EditorBrowsable(EditorBrowsableState.Never)] public virtual async Task> ReadAsync() { DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(Read)}"); @@ -2933,6 +2937,7 @@ public virtual async Task> ReadAsync() /// A will be thrown if /// a failure occurs. /// + [EditorBrowsable(EditorBrowsableState.Never)] public virtual Response Read( CancellationToken cancellationToken = default) { @@ -2980,6 +2985,7 @@ public virtual Response Read( /// A will be thrown if /// a failure occurs. /// + [EditorBrowsable(EditorBrowsableState.Never)] public virtual async Task> ReadAsync( CancellationToken cancellationToken = default) { @@ -3017,12 +3023,12 @@ public virtual async Task> ReadAsync( /// Get Blob. /// /// - /// If provided, only donwload the bytes of the file in the specified + /// If provided, only download the bytes of the file in the specified /// range. If not provided, download the entire file. /// /// /// Optional to add conditions on - /// donwloading this file. + /// downloading this file. /// /// /// When set to true and specified together with the , @@ -3091,12 +3097,12 @@ public virtual Response Read( /// Get Blob. /// /// - /// If provided, only donwload the bytes of the file in the specified + /// If provided, only download the bytes of the file in the specified /// range. If not provided, download the entire file. /// /// /// Optional to add conditions on - /// donwloading this file. + /// downloading this file. /// /// /// When set to true and specified together with the , @@ -3157,7 +3163,7 @@ public virtual async Task> ReadAsync( } /// - /// The + /// The /// operation downloads a file from the service, including its metadata /// and properties. /// @@ -3181,6 +3187,7 @@ public virtual async Task> ReadAsync( /// A will be thrown if /// a failure occurs. /// + [EditorBrowsable(EditorBrowsableState.Never)] public virtual Response Read( DataLakeFileReadOptions options = default, CancellationToken cancellationToken = default) @@ -3211,7 +3218,7 @@ public virtual Response Read( } /// - /// The + /// The /// operation downloads a file from the service, including its metadata /// and properties. /// @@ -3235,6 +3242,7 @@ public virtual Response Read( /// A will be thrown if /// a failure occurs. /// + [EditorBrowsable(EditorBrowsableState.Never)] public virtual async Task> ReadAsync( DataLakeFileReadOptions options = default, CancellationToken cancellationToken = default) @@ -3264,6 +3272,597 @@ public virtual async Task> ReadAsync( scope.Dispose(); } } + #endregion Deprecated + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual Response ReadStreaming() + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadStreaming)}"); + + try + { + scope.Start(); + + Response response = _blockBlobClient.DownloadStreaming(); + + return Response.FromValue( + response.ToDataLakeFileReadStreamingResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual async Task> ReadStreamingAsync() + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadStreaming)}"); + + try + { + scope.Start(); + + Response response = await _blockBlobClient.DownloadStreamingAsync() + .ConfigureAwait(false); + + return Response.FromValue( + response.ToDataLakeFileReadStreamingResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// Optional to propagate + /// notifications that the operation should be cancelled. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual Response ReadStreaming( + CancellationToken cancellationToken = default) + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadStreaming)}"); + + try + { + scope.Start(); + + Response response = _blockBlobClient.DownloadStreaming( + cancellationToken: cancellationToken); + + return Response.FromValue( + response.ToDataLakeFileReadStreamingResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// Optional to propagate + /// notifications that the operation should be cancelled. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual async Task> ReadStreamingAsync( + CancellationToken cancellationToken = default) + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadStreaming)}"); + + try + { + scope.Start(); + + Response response = await _blockBlobClient.DownloadStreamingAsync( + cancellationToken: cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue( + response.ToDataLakeFileReadStreamingResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// Optional parameters. + /// + /// + /// Optional to propagate + /// notifications that the operation should be cancelled. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual Response ReadStreaming( + DataLakeFileReadOptions options = default, + CancellationToken cancellationToken = default) + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadStreaming)}"); + + try + { + scope.Start(); + + Response response = _blockBlobClient.DownloadStreaming( + options: options.ToBlobBaseDownloadOptions(), + cancellationToken: cancellationToken); + + return Response.FromValue( + response.ToDataLakeFileReadStreamingResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// Optional parameters. + /// + /// + /// Optional to propagate + /// notifications that the operation should be cancelled. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual async Task> ReadStreamingAsync( + DataLakeFileReadOptions options = default, + CancellationToken cancellationToken = default) + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadStreaming)}"); + + try + { + scope.Start(); + + Response response = await _blockBlobClient.DownloadStreamingAsync( + options: options.ToBlobBaseDownloadOptions(), + cancellationToken: cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue( + response.ToDataLakeFileReadStreamingResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual Response ReadContent() + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadContent)}"); + + try + { + scope.Start(); + + Response response = _blockBlobClient.DownloadContent(); + + return Response.FromValue( + response.ToDataLakeFileReadResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual async Task> ReadContentAsync() + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadContent)}"); + + try + { + scope.Start(); + + Response response = await _blockBlobClient.DownloadContentAsync() + .ConfigureAwait(false); + + return Response.FromValue( + response.ToDataLakeFileReadResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// Optional to propagate + /// notifications that the operation should be cancelled. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual Response ReadContent( + CancellationToken cancellationToken = default) + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadContent)}"); + + try + { + scope.Start(); + + Response response = _blockBlobClient.DownloadContent( + cancellationToken: cancellationToken); + + return Response.FromValue( + response.ToDataLakeFileReadResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// Optional to propagate + /// notifications that the operation should be cancelled. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual async Task> ReadContentAsync( + CancellationToken cancellationToken = default) + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadContent)}"); + + try + { + scope.Start(); + + Response response = await _blockBlobClient.DownloadContentAsync( + cancellationToken: cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue( + response.ToDataLakeFileReadResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// Optional parameters. + /// + /// + /// Optional to propagate + /// notifications that the operation should be cancelled. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual Response ReadContent( + DataLakeFileReadOptions options = default, + CancellationToken cancellationToken = default) + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadContent)}"); + + try + { + scope.Start(); + + Response response = _blockBlobClient.DownloadContent( + options: options.ToBlobBaseDownloadOptions(), + cancellationToken: cancellationToken); + + return Response.FromValue( + response.ToDataLakeFileReadResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } + + /// + /// The + /// operation downloads a file from the service, including its metadata + /// and properties. + /// + /// For more information, see + /// + /// Get Blob. + /// + /// + /// Optional parameters. + /// + /// + /// Optional to propagate + /// notifications that the operation should be cancelled. + /// + /// + /// A describing the + /// downloaded file. contains + /// the file's data. + /// + /// + /// A will be thrown if + /// a failure occurs. + /// + public virtual async Task> ReadContentAsync( + DataLakeFileReadOptions options = default, + CancellationToken cancellationToken = default) + { + DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(DataLakeFileClient)}.{nameof(ReadContent)}"); + + try + { + scope.Start(); + + Response response = await _blockBlobClient.DownloadContentAsync( + options: options.ToBlobBaseDownloadOptions(), + cancellationToken: cancellationToken) + .ConfigureAwait(false); + + return Response.FromValue( + response.ToDataLakeFileReadResult(), + response.GetRawResponse()); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + finally + { + scope.Dispose(); + } + } #endregion Read Data #region Read To diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeFileReadResult.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeFileReadResult.cs new file mode 100644 index 0000000000000..6059019eb6cdd --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeFileReadResult.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Azure.Storage.Files.DataLake.Models +{ + /// + /// The details and content returned from reading a DataLake File. + /// + public class DataLakeFileReadResult + { + internal DataLakeFileReadResult() { } + + /// + /// Details returned when reading a DataLake file + /// + public FileDownloadDetails Details { get; internal set; } + + /// + /// Content. + /// + public BinaryData Content { get; internal set; } + } +} diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeFileReadStreamingResult.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeFileReadStreamingResult.cs new file mode 100644 index 0000000000000..985b1e9ab8374 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeFileReadStreamingResult.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.IO; +using Azure.Storage.Shared; + +namespace Azure.Storage.Files.DataLake.Models +{ + /// + /// The details and content returned from reading a datalake file. + /// + public class DataLakeFileReadStreamingResult : IDisposable + { + internal DataLakeFileReadStreamingResult() { } + + /// + /// Details returned when reading a datalake file. + /// + public FileDownloadDetails Details { get; internal set; } + + /// + /// Content. + /// + public Stream Content { get; internal set; } + + /// + /// Disposes the by calling Dispose on the underlying stream. + /// + public void Dispose() + { + Content?.Dispose(); + GC.SuppressFinalize(this); + } + } +} diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeModelFactory.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeModelFactory.cs index f4b7370f69f4e..34e280c2b2f63 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeModelFactory.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/Models/DataLakeModelFactory.cs @@ -13,6 +13,34 @@ namespace Azure.Storage.Files.DataLake.Models /// public static partial class DataLakeModelFactory { + #region DataLakeFileReadResult + /// + /// Creates a new instance for mocking. + /// + public static DataLakeFileReadResult DataLakeFileReadResult( + BinaryData content, + FileDownloadDetails details) + => new DataLakeFileReadResult() + { + Content = content, + Details = details + }; + #endregion DataLakeFileReadResult + + #region DataLakeFileReadStreamingResult + /// + /// Creates a new instance for mocking. + /// + public static DataLakeFileReadStreamingResult DataLakeFileReadStreamingResult( + Stream content, + FileDownloadDetails details) + => new DataLakeFileReadStreamingResult() + { + Content = content, + Details = details + }; + #endregion DataLakeFileReadStreamingResult + #region FileDownloadDetails /// /// Creates a new FileDownloadDetails instance for mocking. @@ -235,6 +263,7 @@ public static FileDownloadDetails FileDownloadDetails( /// /// Creates a new instance for mocking. /// + [EditorBrowsable(EditorBrowsableState.Never)] public static FileDownloadInfo FileDownloadInfo( long contentLength, Stream content, diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs index 6d9f0d5750800..b0be1c794ff28 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileClientTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Mime; using System.Reflection; using System.Security.Cryptography; using System.Text; @@ -3455,6 +3456,71 @@ public async Task ReadAsync() TestHelper.AssertSequenceEqual(data, actual.ToArray()); } + [RecordedTest] + public async Task ReadStreamingAsync() + { + await using DisposingFileSystem test = await GetNewFileSystem(); + + // Arrange + byte[] data = GetRandomBuffer(Constants.KB); + DataLakeFileClient fileClient = await test.FileSystem.CreateFileAsync(GetNewFileName()); + using (MemoryStream stream = new MemoryStream(data)) + { + await fileClient.AppendAsync(stream, 0); + } + + await fileClient.FlushAsync(Constants.KB); + + // Act + Response response = await fileClient.ReadStreamingAsync(); + + // Assert + Assert.IsNotNull(response.Value.Details.LastModified); + Assert.IsNotNull(response.Value.Details.AcceptRanges); + Assert.IsNotNull(response.Value.Details.ETag); + Assert.IsNotNull(response.Value.Details.LeaseStatus); + Assert.IsNotNull(response.Value.Details.LeaseState); + Assert.IsNotNull(response.Value.Details.IsServerEncrypted); + Assert.IsNotNull(response.Value.Details.CreatedOn); + Assert.IsNotNull(response.Value.Details.Metadata); + + MemoryStream actual = new MemoryStream(); + await response.Value.Content.CopyToAsync(actual); + TestHelper.AssertSequenceEqual(data, actual.ToArray()); + } + + [RecordedTest] + public async Task ReadContentAsync() + { + await using DisposingFileSystem test = await GetNewFileSystem(); + + // Arrange + byte[] data = GetRandomBuffer(Constants.KB); + DataLakeFileClient fileClient = await test.FileSystem.CreateFileAsync(GetNewFileName()); + using (MemoryStream stream = new MemoryStream(data)) + { + await fileClient.AppendAsync(stream, 0); + } + + await fileClient.FlushAsync(Constants.KB); + + // Act + Response response = await fileClient.ReadContentAsync(); + + // Assert + Assert.IsNotNull(response.Value.Details.LastModified); + Assert.IsNotNull(response.Value.Details.AcceptRanges); + Assert.IsNotNull(response.Value.Details.ETag); + Assert.IsNotNull(response.Value.Details.LeaseStatus); + Assert.IsNotNull(response.Value.Details.LeaseState); + Assert.IsNotNull(response.Value.Details.IsServerEncrypted); + Assert.IsNotNull(response.Value.Details.CreatedOn); + Assert.IsNotNull(response.Value.Details.Metadata); + + byte[] actual = response.Value.Content.ToArray(); + TestHelper.AssertSequenceEqual(data, actual); + } + [RecordedTest] [ServiceVersion(Min = DataLakeClientOptions.ServiceVersion.V2024_05_04)] public async Task ReadAsyncACL() @@ -3502,6 +3568,97 @@ public async Task ReadAsyncACL() TestHelper.AssertSequenceEqual(data, actual.ToArray()); } + [RecordedTest] + [ServiceVersion(Min = DataLakeClientOptions.ServiceVersion.V2024_05_04)] + public async Task ReadStreamingAsyncACL() + { + await using DisposingFileSystem test = await GetNewFileSystem(publicAccessType: PublicAccessType.None); + DataLakeDirectoryClient directory = await test.FileSystem.CreateDirectoryAsync(GetNewDirectoryName()); + + DataLakeFileClient fileClient = InstrumentClient(directory.GetFileClient(GetNewFileName())); + + DataLakePathCreateOptions options = new DataLakePathCreateOptions + { + AccessOptions = new DataLakeAccessOptions + { + AccessControlList = AccessControlList + } + }; + + await fileClient.CreateAsync(options: options); + + // Arrange + var data = GetRandomBuffer(Constants.KB); + using (var stream = new MemoryStream(data)) + { + await fileClient.AppendAsync(stream, 0); + } + + await fileClient.FlushAsync(Constants.KB); + + // Act + Response response = await fileClient.ReadStreamingAsync(); + + // Assert + Assert.IsNotNull(response.Value.Details.LastModified); + Assert.IsNotNull(response.Value.Details.AcceptRanges); + Assert.IsNotNull(response.Value.Details.ETag); + Assert.IsNotNull(response.Value.Details.LeaseStatus); + Assert.IsNotNull(response.Value.Details.LeaseState); + Assert.IsNotNull(response.Value.Details.IsServerEncrypted); + Assert.IsNotNull(response.Value.Details.CreatedOn); + AssertAccessControlListEquality(AccessControlList, response.Value.Details.AccessControlList.ToList()); + + var actual = new MemoryStream(); + await response.Value.Content.CopyToAsync(actual); + TestHelper.AssertSequenceEqual(data, actual.ToArray()); + } + + [RecordedTest] + [ServiceVersion(Min = DataLakeClientOptions.ServiceVersion.V2024_05_04)] + public async Task ReadContentAsyncACL() + { + await using DisposingFileSystem test = await GetNewFileSystem(publicAccessType: PublicAccessType.None); + DataLakeDirectoryClient directory = await test.FileSystem.CreateDirectoryAsync(GetNewDirectoryName()); + + DataLakeFileClient fileClient = InstrumentClient(directory.GetFileClient(GetNewFileName())); + + DataLakePathCreateOptions options = new DataLakePathCreateOptions + { + AccessOptions = new DataLakeAccessOptions + { + AccessControlList = AccessControlList + } + }; + + await fileClient.CreateAsync(options: options); + + // Arrange + var data = GetRandomBuffer(Constants.KB); + using (var stream = new MemoryStream(data)) + { + await fileClient.AppendAsync(stream, 0); + } + + await fileClient.FlushAsync(Constants.KB); + + // Act + Response response = await fileClient.ReadContentAsync(); + + // Assert + Assert.IsNotNull(response.Value.Details.LastModified); + Assert.IsNotNull(response.Value.Details.AcceptRanges); + Assert.IsNotNull(response.Value.Details.ETag); + Assert.IsNotNull(response.Value.Details.LeaseStatus); + Assert.IsNotNull(response.Value.Details.LeaseState); + Assert.IsNotNull(response.Value.Details.IsServerEncrypted); + Assert.IsNotNull(response.Value.Details.CreatedOn); + AssertAccessControlListEquality(AccessControlList, response.Value.Details.AccessControlList.ToList()); + + byte[] actual = response.Value.Content.ToArray(); + TestHelper.AssertSequenceEqual(data, actual); + } + [RecordedTest] [ServiceVersion(Min = DataLakeClientOptions.ServiceVersion.V2024_05_04)] public async Task GetPropertiesAsyncACL() @@ -3630,6 +3787,76 @@ public async Task ReadAsync_Conditions() } } + [RecordedTest] + public async Task ReadStreamingAsync_Conditions() + { + var garbageLeaseId = GetGarbageLeaseId(); + foreach (AccessConditionParameters parameters in Conditions_Data) + { + await using DisposingFileSystem test = await GetNewFileSystem(); + + // Arrange + var data = GetRandomBuffer(Constants.KB); + DataLakeFileClient file = await test.FileSystem.CreateFileAsync(GetNewFileName()); + using (var stream = new MemoryStream(data)) + { + await file.AppendAsync(stream, 0); + } + + await file.FlushAsync(Constants.KB); + + parameters.Match = await SetupPathMatchCondition(file, parameters.Match); + parameters.LeaseId = await SetupPathLeaseCondition(file, parameters.LeaseId, garbageLeaseId); + DataLakeRequestConditions conditions = BuildDataLakeRequestConditions( + parameters: parameters, + lease: true); + + // Act + Response response = await file.ReadStreamingAsync(new DataLakeFileReadOptions + { + Conditions = conditions + }); + + // Assert + Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); + } + } + + [RecordedTest] + public async Task ReadContentAsync_Conditions() + { + var garbageLeaseId = GetGarbageLeaseId(); + foreach (AccessConditionParameters parameters in Conditions_Data) + { + await using DisposingFileSystem test = await GetNewFileSystem(); + + // Arrange + var data = GetRandomBuffer(Constants.KB); + DataLakeFileClient file = await test.FileSystem.CreateFileAsync(GetNewFileName()); + using (var stream = new MemoryStream(data)) + { + await file.AppendAsync(stream, 0); + } + + await file.FlushAsync(Constants.KB); + + parameters.Match = await SetupPathMatchCondition(file, parameters.Match); + parameters.LeaseId = await SetupPathLeaseCondition(file, parameters.LeaseId, garbageLeaseId); + DataLakeRequestConditions conditions = BuildDataLakeRequestConditions( + parameters: parameters, + lease: true); + + // Act + Response response = await file.ReadContentAsync(new DataLakeFileReadOptions + { + Conditions = conditions + }); + + // Assert + Assert.IsNotNull(response.GetRawResponse().Headers.RequestId); + } + } + [RecordedTest] public async Task ReadAsync_ConditionsFail() { @@ -3663,6 +3890,72 @@ await TestHelper.CatchAsync( } } + [RecordedTest] + public async Task ReadStreamingAsync_ConditionsFail() + { + var garbageLeaseId = GetGarbageLeaseId(); + foreach (AccessConditionParameters parameters in GetConditionsFail_Data(garbageLeaseId)) + { + await using DisposingFileSystem test = await GetNewFileSystem(); + + // Arrange + var data = GetRandomBuffer(Constants.KB); + DataLakeFileClient file = await test.FileSystem.CreateFileAsync(GetNewFileName()); + using (var stream = new MemoryStream(data)) + { + await file.AppendAsync(stream, 0); + } + + await file.FlushAsync(Constants.KB); + + parameters.NoneMatch = await SetupPathMatchCondition(file, parameters.NoneMatch); + DataLakeRequestConditions conditions = BuildDataLakeRequestConditions(parameters); + + // Act + await TestHelper.CatchAsync( + async () => + { + var _ = (await file.ReadStreamingAsync(new DataLakeFileReadOptions + { + Conditions = conditions + })).Value; + }); + } + } + + [RecordedTest] + public async Task ReadContentAsync_ConditionsFail() + { + var garbageLeaseId = GetGarbageLeaseId(); + foreach (AccessConditionParameters parameters in GetConditionsFail_Data(garbageLeaseId)) + { + await using DisposingFileSystem test = await GetNewFileSystem(); + + // Arrange + var data = GetRandomBuffer(Constants.KB); + DataLakeFileClient file = await test.FileSystem.CreateFileAsync(GetNewFileName()); + using (var stream = new MemoryStream(data)) + { + await file.AppendAsync(stream, 0); + } + + await file.FlushAsync(Constants.KB); + + parameters.NoneMatch = await SetupPathMatchCondition(file, parameters.NoneMatch); + DataLakeRequestConditions conditions = BuildDataLakeRequestConditions(parameters); + + // Act + await TestHelper.CatchAsync( + async () => + { + var _ = (await file.ReadContentAsync(new DataLakeFileReadOptions + { + Conditions = conditions + })).Value; + }); + } + } + [RecordedTest] public async Task ReadAsync_Error() { @@ -3677,6 +3970,34 @@ await TestHelper.AssertExpectedExceptionAsync( e => Assert.AreEqual("BlobNotFound", e.ErrorCode)); } + [RecordedTest] + public async Task ReadStreamingAsync_Error() + { + await using DisposingFileSystem test = await GetNewFileSystem(); + + // Arrange + DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); + + // Act + await TestHelper.AssertExpectedExceptionAsync( + file.ReadStreamingAsync(), + e => Assert.AreEqual("BlobNotFound", e.ErrorCode)); + } + + [RecordedTest] + public async Task ReadContentAsync_Error() + { + await using DisposingFileSystem test = await GetNewFileSystem(); + + // Arrange + DataLakeFileClient file = InstrumentClient(test.FileSystem.GetFileClient(GetNewFileName())); + + // Act + await TestHelper.AssertExpectedExceptionAsync( + file.ReadContentAsync(), + e => Assert.AreEqual("BlobNotFound", e.ErrorCode)); + } + [RecordedTest] public async Task AcquireLeaseAsync() {