public async Task Read(string path, Stream toStream, CancellationToken token = default) { path = WithBasePath(path); toStream.VerifyNotNull(nameof(toStream)); _logger.LogTrace($"Reading {path} to stream"); DataLakeFileClient file = _fileSystem.GetFileClient(path); await file.ReadToAsync(toStream, cancellationToken : token); }
public async Task Download(string path, Stream toStream, CancellationToken token) { path.VerifyNotEmpty(nameof(path)); toStream.VerifyNotNull(nameof(toStream)); _logger.LogTrace($"{nameof(Download)} downloading {path} to stream"); DataLakeFileClient file = _fileSystem.GetFileClient(path); await file.ReadToAsync(toStream, cancellationToken : token); }
public async Task ReadToAsync() { // 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 directly to a file. // For larger files, ReadToAsync() will download the file in multiple parallel requests. await file.ReadToAsync(downloadPath); // Verify the contents Assert.AreEqual(SampleFileContent, File.ReadAllText(downloadPath)); } finally { // Clean up after the test when we're finished await filesystem.DeleteAsync(); } }