Skip to content

Commit

Permalink
Add CompressionDecorator.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Nov 1, 2024
1 parent 07c1f12 commit 53613bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Structural/DesignPatterns.Decorator/CompressionDecorator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.IO.Compression;

namespace DesignPatterns.Decorator;

internal class CompressionDecorator : UploaderDecorator
Expand All @@ -9,10 +11,9 @@ public CompressionDecorator(IFileUploader uploader)

public override async Task Upload(string name, Stream stream)
{
// TODO: add compression logic here.
Console.WriteLine($"{nameof(CompressionDecorator)}.{nameof(Upload)}: started compressing a file...");
await Task.Delay(1000);
Console.WriteLine($"{nameof(CompressionDecorator)}.{nameof(Upload)}: completed compressing a file.");
await base.Upload(name, stream);
using MemoryStream compressedStream = new MemoryStream();
await using var compressor = new GZipStream(compressedStream, CompressionMode.Compress);
await stream.CopyToAsync(compressor);
await base.Upload(name, compressor.BaseStream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(MSBuildProjectName).UnitTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>

0 comments on commit 53613bd

Please sign in to comment.