Skip to content

Commit

Permalink
Apply remaining feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
buyaa-n committed Jul 26, 2024
1 parent 6a34ad4 commit d0335f8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,11 @@ async Task<long> GetLengthAsync(CompressionLevel compressionLevel)
public async Task RoundTripWithZLibCompressionOptions(string testFile, ZLibCompressionOptions options)
{
using var uncompressedStream = await LocalMemoryStream.readAppFileAsync(testFile);
var compressedStream = CompressTestFile(uncompressedStream, options);
var compressedStream = await CompressTestFile(uncompressedStream, options);
using var decompressor = CreateStream(compressedStream, mode: CompressionMode.Decompress);
using var decompressorOutput = new MemoryStream();
await decompressor.CopyToAsync(decompressorOutput);
decompressor.Dispose();
await decompressor.DisposeAsync();
decompressorOutput.Position = 0;
uncompressedStream.Position = 0;

Expand All @@ -520,24 +520,24 @@ public async Task RoundTripWithZLibCompressionOptions(string testFile, ZLibCompr
}
}

private MemoryStream CompressTestFile(LocalMemoryStream testStream, ZLibCompressionOptions options)
private async Task<MemoryStream> CompressTestFile(LocalMemoryStream testStream, ZLibCompressionOptions options)
{
var compressorOutput = new MemoryStream();
using (var compressionStream = CreateStream(compressorOutput, options, leaveOpen: true))
{
var buffer = new byte[4096];
int bytesRead;
while ((bytesRead = testStream.Read(buffer, 0, buffer.Length)) > 0)
while ((bytesRead = await testStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
compressionStream.Write(buffer, 0, bytesRead);
await compressionStream.WriteAsync(buffer, 0, bytesRead);
}
}

compressorOutput.Position = 0;
return compressorOutput;
}

protected async void CompressionLevel_SizeInOrderBase(string testFile)
protected async Task CompressionLevel_SizeInOrderBase(string testFile)
{
using var uncompressedStream = await LocalMemoryStream.readAppFileAsync(testFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ZLibCompressionStrategy CompressionStrategy
}

/// <summary>
/// Specifies the compression algorithm to use for compression stream.
/// Defines the compression algorithms that can be used for <see cref="DeflateStream"/>, <see cref="GZipStream"/> or <see cref="ZLibStream"/>.
/// </summary>
public enum ZLibCompressionStrategy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati

[Theory]
[MemberData(nameof(UncompressedTestFilesZLib))]
public void ZLibCompressionLevel_SizeInOrder(string testFile)
public async Task ZLibCompressionLevel_SizeInOrder(string testFile)
{
CompressionLevel_SizeInOrderBase(testFile);
await CompressionLevel_SizeInOrderBase(testFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati

[Theory]
[MemberData(nameof(UncompressedTestFilesZLib))]
public void ZLibCompressionLevel_SizeInOrder(string testFile)
public async Task ZLibCompressionLevel_SizeInOrder(string testFile)
{
CompressionLevel_SizeInOrderBase(testFile);
await CompressionLevel_SizeInOrderBase(testFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Compression.Tests;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -155,9 +153,9 @@ public void StreamTruncation_IsDetected(TestScenario testScenario)

[Theory]
[MemberData(nameof(UncompressedTestFilesZLib))]
public void ZLibCompressionLevel_SizeInOrder(string testFile)
public async Task ZLibCompressionLevel_SizeInOrder(string testFile)
{
CompressionLevel_SizeInOrderBase(testFile);
await CompressionLevel_SizeInOrderBase(testFile);
}
}
}

0 comments on commit d0335f8

Please sign in to comment.