123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.IO;
- namespace SharpCompress.IO
- {
- public class NonDisposingStream : Stream
- {
- public NonDisposingStream(Stream stream, bool throwOnDispose = false)
- {
- Stream = stream;
- ThrowOnDispose = throwOnDispose;
- }
- public bool ThrowOnDispose { get; set; }
- protected override void Dispose(bool disposing)
- {
- GC.SuppressFinalize(this);
- if (ThrowOnDispose)
- {
- throw new InvalidOperationException();
- }
- }
- protected Stream Stream { get; }
- public override bool CanRead => Stream.CanRead;
- public override bool CanSeek => Stream.CanSeek;
- public override bool CanWrite => Stream.CanWrite;
- 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)
- {
- return Stream.Read(buffer, offset, count);
- }
- public override int ReadByte()
- {
- return Stream.ReadByte();
- }
- public override long Seek(long offset, SeekOrigin origin)
- {
- return 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);
- }
- public override void WriteByte(byte value)
- {
- Stream.WriteByte(value);
- }
- }
- }
|