Fix release review findings in RAR, GZip, and split ZIP parsing

This commit is contained in:
Adam Hathcock
2026-10-10 08:22:55 +01:00
parent e4193af83b
commit ab3ac18e98
16 changed files with 648 additions and 57 deletions

View File

@@ -0,0 +1,28 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace SharpCompress.Test.Mocks;
// Exercise legal partial reads through every stream read overload used by the parsers.
internal sealed class ShortReadStream(Stream stream, int maxReadSize = 1, bool seekable = true)
: TestStream(stream, read: true, write: false, seek: seekable)
{
public override int Read(byte[] buffer, int offset, int count) =>
base.Read(buffer, offset, Math.Min(count, maxReadSize));
public override Task<int> ReadAsync(
byte[] buffer,
int offset,
int count,
CancellationToken cancellationToken
) => base.ReadAsync(buffer, offset, Math.Min(count, maxReadSize), cancellationToken);
#if !LEGACY_DOTNET
public override ValueTask<int> ReadAsync(
Memory<byte> buffer,
CancellationToken cancellationToken = default
) => base.ReadAsync(buffer.Slice(0, Math.Min(buffer.Length, maxReadSize)), cancellationToken);
#endif
}