-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
…ried on non-seekable streams, causing a failure.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
namespace Imageflow.Test; | ||
|
||
using System; | ||
using System.IO; | ||
|
||
public class NonSeekableReadStream : Stream | ||
{ | ||
private byte[] data; | ||
private long position = 0; // Current position within the data | ||
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 9 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
|
||
|
||
public NonSeekableReadStream(byte[] dataSource) | ||
{ | ||
data = dataSource ?? throw new ArgumentNullException(nameof(dataSource)); | ||
} | ||
|
||
public override bool CanRead => true; | ||
public override bool CanSeek => false; | ||
public override bool CanWrite => false; | ||
|
||
public override long Length => data.Length; | ||
|
||
public override long Position | ||
{ | ||
get => throw new NotSupportedException("Seeking not supported."); | ||
set => throw new NotSupportedException("Seeking not supported."); | ||
} | ||
|
||
public override void Flush() | ||
{ | ||
// No-op for read-only stream | ||
} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
if (buffer == null) throw new ArgumentNullException(nameof(buffer)); | ||
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 35 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
|
||
if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException("offset or count is negative."); | ||
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (macos-11.0)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (ubuntu-latest, 8.0.1)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
Check warning on line 36 in tests/Imageflow.Test/NonSeekableReadStream.cs GitHub Actions / build (windows-latest, true, true, true, true)
|
||
if (buffer.Length - offset < count) throw new ArgumentException("The sum of offset and count is greater than the buffer length."); | ||
|
||
int available = data.Length - (int)position; | ||
if (available <= 0) return 0; // End of stream | ||
|
||
int toCopy = Math.Min(available, count); | ||
Array.Copy(data, position, buffer, offset, toCopy); | ||
position += toCopy; | ||
return toCopy; | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) | ||
{ | ||
throw new NotSupportedException("Seeking not supported."); | ||
} | ||
|
||
public override void SetLength(long value) | ||
{ | ||
throw new NotSupportedException("Setting length not supported."); | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
throw new NotSupportedException("Writing not supported."); | ||
} | ||
} |