45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
internal class LargeStreamResult : System.IO.Stream
|
|
{
|
|
private long _position = 0;
|
|
private const long _length = 8L * 1024L * 1024L * 1024L; // 8 GB
|
|
|
|
public override bool CanRead => true;
|
|
public override bool CanSeek => true;
|
|
public override bool CanWrite => false;
|
|
public override long Length => _length;
|
|
public override long Position { get => _position; set => _position = value; }
|
|
|
|
public override void Flush() { }
|
|
|
|
public override int Read(byte[] buffer, int offset, int count)
|
|
{
|
|
int bytesToRead = (int)Math.Min(count, _length - _position);
|
|
if (bytesToRead <= 0)
|
|
return 0;
|
|
|
|
_position += bytesToRead;
|
|
return bytesToRead;
|
|
}
|
|
|
|
public override long Seek(long offset, System.IO.SeekOrigin origin)
|
|
{
|
|
switch (origin)
|
|
{
|
|
case System.IO.SeekOrigin.Begin:
|
|
_position = offset;
|
|
break;
|
|
case System.IO.SeekOrigin.Current:
|
|
_position += offset;
|
|
break;
|
|
case System.IO.SeekOrigin.End:
|
|
_position = _length + offset;
|
|
break;
|
|
}
|
|
return _position;
|
|
}
|
|
|
|
public override void SetLength(long value) { }
|
|
|
|
public override void Write(byte[] buffer, int offset, int count) { }
|
|
}
|