mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-12 05:25:03 +00:00
- Added IsArchiveAsync interface method to IFactory - Implemented async versions of IsZipFile, IsZipMulti, IsGZipFile - Updated ZipFactory and GZipFactory to override IsArchiveAsync - Updated ReaderFactory.OpenAsync to use IsArchiveAsync - Fixed Zip_Reader_Disposal_Test2_Async to use ReaderFactory.OpenAsync - Fixed TestStream to properly forward ReadAsync calls - Removed BufferedStream wrapping from AsyncBinaryReader as it uses sync Read - Added default implementation in Factory base class Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SharpCompress.Test.Mocks;
|
|
|
|
public class TestStream(Stream stream, bool read, bool write, bool seek) : Stream
|
|
{
|
|
public TestStream(Stream stream)
|
|
: this(stream, stream.CanRead, stream.CanWrite, stream.CanSeek) { }
|
|
|
|
public bool IsDisposed { get; private set; }
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
stream.Dispose();
|
|
IsDisposed = true;
|
|
}
|
|
|
|
public override bool CanRead { get; } = read;
|
|
|
|
public override bool CanSeek { get; } = seek;
|
|
|
|
public override bool CanWrite { get; } = write;
|
|
|
|
public override void Flush() => stream.Flush();
|
|
|
|
public override long Length => stream.Length;
|
|
|
|
public override long Position
|
|
{
|
|
get => stream.Position;
|
|
set => stream.Position = value;
|
|
}
|
|
|
|
public override int Read(byte[] buffer, int offset, int count) =>
|
|
stream.Read(buffer, offset, count);
|
|
|
|
public override Task<int> ReadAsync(
|
|
byte[] buffer,
|
|
int offset,
|
|
int count,
|
|
CancellationToken cancellationToken
|
|
) => stream.ReadAsync(buffer, offset, count, cancellationToken);
|
|
|
|
#if !NETFRAMEWORK && !NETSTANDARD2_0
|
|
public override ValueTask<int> ReadAsync(
|
|
Memory<byte> buffer,
|
|
CancellationToken cancellationToken = default
|
|
) => stream.ReadAsync(buffer, cancellationToken);
|
|
#endif
|
|
|
|
public override long Seek(long offset, SeekOrigin origin) => stream.Seek(offset, origin);
|
|
|
|
public override void SetLength(long value) => stream.SetLength(value);
|
|
|
|
public override void Write(byte[] buffer, int offset, int count) =>
|
|
stream.Write(buffer, offset, count);
|
|
}
|