// Copyright 2017-2018 Alexander Luzgarev using System; using System.IO; namespace MatFileHandler.Tests { /// /// A stream which wraps another stream and only reads one byte at a time, /// while forbidding seeking in it. /// internal class PartialUnseekableReadStream : Stream { private readonly Stream _baseStream; /// /// Initializes a new instance of the class. /// /// The stream to wrap. public PartialUnseekableReadStream(Stream baseStream) { _baseStream = baseStream; } /// public override bool CanRead => _baseStream.CanRead; /// public override bool CanSeek => false; /// public override bool CanWrite => false; /// public override long Length => _baseStream.Length; /// public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } /// public override void Flush() { _baseStream.Flush(); } /// public override int Read(byte[] buffer, int offset, int count) { return _baseStream.Read(buffer, offset, Math.Min(1, count)); } /// 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) { throw new NotImplementedException(); } /// protected override void Dispose(bool disposing) { if (disposing) { _baseStream.Dispose(); } base.Dispose(disposing); } } }