NetworkQualityServer/AS1024.NetworkQuality.Serve.../Simulators/LargeStreamResult.cs

48 lines
1.3 KiB
C#

using System;
using System.IO;
internal class LargeStreamResult : 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, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin.Begin:
_position = offset;
break;
case SeekOrigin.Current:
_position += offset;
break;
case SeekOrigin.End:
_position = _length + offset;
break;
}
return _position;
}
public override void SetLength(long value) { }
public override void Write(byte[] buffer, int offset, int count) { }
}