Skip to content

Commit

Permalink
Merge main to issue-94, update version and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalFrends1 committed Dec 11, 2024
2 parents c41305c + 52825a4 commit d0de41a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
6 changes: 5 additions & 1 deletion Frends.AzureBlobStorage.UploadBlob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<Version>2.1.1</Version>
<Version>2.3.0</Version>
<Authors>Frends</Authors>
<Copyright>Frends</Copyright>
<Company>Frends</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit d0de41a

Please sign in to comment.