// 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.
///
internal class PartialReadStream : Stream
{
private readonly Stream _baseStream;
///
/// Initializes a new instance of the class.
///
/// The stream to wrap.
public PartialReadStream(Stream baseStream)
{
_baseStream = baseStream;
}
///
public override bool CanRead => _baseStream.CanRead;
///
public override bool CanSeek => _baseStream.CanSeek;
///
public override bool CanWrite => false;
///
public override long Length => _baseStream.Length;
///
public override long Position
{
get => _baseStream.Position;
set => _baseStream.Position = value;
}
///
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)
{
return _baseStream.Seek(offset, origin);
}
///
public override void SetLength(long value)
{
_baseStream.SetLength(value);
}
///
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);
}
}
}