diff --git a/Frends.AzureBlobStorage.UploadBlob/CHANGELOG.md b/Frends.AzureBlobStorage.UploadBlob/CHANGELOG.md index 4e77018..fcee8d4 100644 --- a/Frends.AzureBlobStorage.UploadBlob/CHANGELOG.md +++ b/Frends.AzureBlobStorage.UploadBlob/CHANGELOG.md @@ -1,9 +1,13 @@ # Changelog -## [2.1.1] - 2024-12-11 +## [2.3.0] - 2024-12-11 ### Updated - Removed progress handler +## [2.2.0] - 2024-12-05 +### Updated +- Fixed GZip compression + ## [2.1.0] - 2024-08-21 ### Updated - Updated Azure.Identity to version 1.12.0. diff --git a/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob.Tests/UnitTests.cs b/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob.Tests/UnitTests.cs index acbdddf..664c03c 100644 --- a/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob.Tests/UnitTests.cs +++ b/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob.Tests/UnitTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.IO.Compression; using System.Threading.Tasks; namespace Frends.AzureBlobStorage.UploadBlob.Tests; @@ -183,6 +184,28 @@ public async Task UploadFile_Compress() Assert.IsTrue(result.Data.ContainsValue($"{container.Uri}/compress.gz")); Assert.IsTrue(await container.GetBlobClient("compress.gz").ExistsAsync(), "Uploaded SomeBlob blob should exist"); + if (blobtype == AzureBlobType.Block) + { + var downloadedFilePath = Path.GetTempFileName(); + try + { + await container.GetBlobClient("compress.gz").DownloadToAsync(downloadedFilePath); + + using (var downloadedStream = File.OpenRead(downloadedFilePath)) + using (var gzipStream = new GZipStream(downloadedStream, CompressionMode.Decompress)) + using (var reader = new StreamReader(gzipStream)) + { + var decompressedContent = await reader.ReadToEndAsync(); + var originalContent = await File.ReadAllTextAsync(_source.SourceFile); + Assert.AreEqual(originalContent, decompressedContent, "Decompressed content should match original"); + } + } + finally + { + if (File.Exists(downloadedFilePath)) File.Delete(downloadedFilePath); + } + } + // OAuth var result2 = await AzureBlobStorage.UploadBlob(_source, _destinationOA, _options, default); Assert.IsTrue(result2.Success); diff --git a/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob.csproj b/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob.csproj index 1980e82..dbc4a7f 100644 --- a/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob.csproj +++ b/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob.csproj @@ -2,7 +2,7 @@ net6.0 - 2.1.1 + 2.3.0 Frends Frends Frends diff --git a/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob/UploadBlob.cs b/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob/UploadBlob.cs index 11ea229..b081d08 100644 --- a/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob/UploadBlob.cs +++ b/Frends.AzureBlobStorage.UploadBlob/Frends.AzureBlobStorage.UploadBlob/UploadBlob.cs @@ -417,31 +417,29 @@ private static Stream GetStream(bool compress, bool fromString, Encoding encodin if (!compress) { - using (var reader = new StreamReader(fileStream, encoding)) bytes = encoding.GetBytes(reader.ReadToEnd()); + using var reader = new StreamReader(fileStream, encoding); + bytes = encoding.GetBytes(reader.ReadToEnd()); return new MemoryStream(bytes); } using var outStream = new MemoryStream(); - using var gzip = new GZipStream(outStream, CompressionMode.Compress); - - if (!fromString) + using (var gzip = new GZipStream(outStream, CompressionMode.Compress, true)) { - fileStream.CopyTo(gzip); - } - else - { - using var reader = new StreamReader(fileStream, encoding); - var content = reader.ReadToEnd(); - using var encodedMemory = new MemoryStream(encoding.GetBytes(content)); - encodedMemory.CopyTo(gzip); + if (!fromString) + { + fileStream.CopyTo(gzip); + } + else + { + using var reader = new StreamReader(fileStream, encoding); + var content = reader.ReadToEnd(); + using var encodedMemory = new MemoryStream(encoding.GetBytes(content)); + encodedMemory.CopyTo(gzip); + } } bytes = outStream.ToArray(); - - fileStream.Close(); - - var memStream = new MemoryStream(bytes); - return memStream; + return new MemoryStream(bytes); } finally {