mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-07-27 03:13:13 +00:00
Update the sub-stream classes to all inherit from `NonDisposingStream`. This allows them to correctly implement the `Dispose` pattern, and delegate the actual disposal to `NonDisposingStream`. In doing so, we need to remove some redundant overrides from `NonDisposingStream`, otherwise `BufferedSubStream` would use the overrides inherited from `NonDisposingStream` instead of the ones inherited from `Stream` (i.e. delegate `ReadByte` to `Read`).
56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace SharpCompress.IO
|
|
{
|
|
internal class CountingWritableSubStream : NonDisposingStream
|
|
{
|
|
internal CountingWritableSubStream(Stream stream) : base(stream, throwOnDispose: false)
|
|
{
|
|
}
|
|
|
|
public ulong Count { get; private set; }
|
|
|
|
public override bool CanRead => false;
|
|
|
|
public override bool CanSeek => false;
|
|
|
|
public override bool CanWrite => true;
|
|
|
|
public override void Flush()
|
|
{
|
|
Stream.Flush();
|
|
}
|
|
|
|
public override long Length => throw new NotSupportedException();
|
|
|
|
public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
|
|
|
|
public override int Read(byte[] buffer, int offset, int count)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override long Seek(long offset, SeekOrigin origin)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override void SetLength(long value)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override void Write(byte[] buffer, int offset, int count)
|
|
{
|
|
Stream.Write(buffer, offset, count);
|
|
Count += (uint)count;
|
|
}
|
|
|
|
public override void WriteByte(byte value)
|
|
{
|
|
Stream.WriteByte(value);
|
|
++Count;
|
|
}
|
|
}
|
|
} |