diff --git a/Structural/DesignPatterns.Decorator/CompressionDecorator.cs b/Structural/DesignPatterns.Decorator/CompressionDecorator.cs index 9780e2b..ca11ab7 100644 --- a/Structural/DesignPatterns.Decorator/CompressionDecorator.cs +++ b/Structural/DesignPatterns.Decorator/CompressionDecorator.cs @@ -1,3 +1,5 @@ +using System.IO.Compression; + namespace DesignPatterns.Decorator; internal class CompressionDecorator : UploaderDecorator @@ -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); } } diff --git a/Structural/DesignPatterns.Decorator/DesignPatterns.Decorator.csproj b/Structural/DesignPatterns.Decorator/DesignPatterns.Decorator.csproj index 2f4fc77..844e1c1 100644 --- a/Structural/DesignPatterns.Decorator/DesignPatterns.Decorator.csproj +++ b/Structural/DesignPatterns.Decorator/DesignPatterns.Decorator.csproj @@ -7,4 +7,10 @@ enable + + + <_Parameter1>$(MSBuildProjectName).UnitTests + + +