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 27, 2024
1 parent 6a34ad4 commit 35b3f9f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 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 @@ -16,14 +16,14 @@ public sealed partial class BrotliStream : Stream
/// <summary>Initializes a new instance of the <see cref="System.IO.Compression.BrotliStream" /> class by using the specified stream and compression level.</summary>
/// <param name="stream">The stream to which compressed data is written.</param>
/// <param name="compressionLevel">One of the enumeration values that indicates whether to emphasize speed or compression efficiency when compressing data to the stream.</param>
/// <exception cref="ArgumentNullException"/><paramref name="stream"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is <see langword="null" />.</exception>
public BrotliStream(Stream stream, CompressionLevel compressionLevel) : this(stream, compressionLevel, leaveOpen: false) { }

/// <summary>Initializes a new instance of the <see cref="System.IO.Compression.BrotliStream" /> class by using the specified stream and compression level, and optionally leaves the stream open.</summary>
/// <param name="stream">The stream to which compressed data is written.</param>
/// <param name="compressionLevel">One of the enumeration values that indicates whether to emphasize speed or compression efficiency when compressing data to the stream.</param>
/// <param name="leaveOpen"><see langword="true" /> to leave the stream open after disposing the <see cref="System.IO.Compression.BrotliStream" /> object; otherwise, <see langword="false" />.</param>
/// <exception cref="ArgumentNullException"/><paramref name="stream"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is <see langword="null" />.</exception>
public BrotliStream(Stream stream, CompressionLevel compressionLevel, bool leaveOpen) : this(stream, CompressionMode.Compress, leaveOpen)
{
_encoder.SetQuality(BrotliUtils.GetQualityFromCompressionLevel(compressionLevel));
Expand All @@ -35,7 +35,7 @@ public BrotliStream(Stream stream, CompressionLevel compressionLevel, bool leave
/// <param name="stream">The stream to which compressed data is written.</param>
/// <param name="compressionOptions">The Brotli options for fine tuning the compression stream.</param>
/// <param name="leaveOpen"><see langword="true" /> to leave the stream open after disposing the <see cref="System.IO.Compression.BrotliStream" /> object; otherwise, <see langword="false" />.</param>
/// <exception cref="ArgumentNullException"/><paramref name="stream"/> or <paramref name="compressionOptions"/> is <see langword="null" />.</exception>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> or <paramref name="compressionOptions"/> is <see langword="null" />.</exception>
public BrotliStream(Stream stream, BrotliCompressionOptions compressionOptions, bool leaveOpen = false) : this(stream, CompressionMode.Compress, leaveOpen)
{
ArgumentNullException.ThrowIfNull(compressionOptions);
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 35b3f9f

Please sign in to comment.