Skip to content

Commit 9473c1a

Browse files
author
SpaceCheetah
committed
Support seeking past the end of a file
1 parent d2b3788 commit 9473c1a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

LiteDB/Client/Storage/LiteFileStream.Read.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public partial class LiteFileStream<TFileId> : Stream
1010
public override int Read(byte[] buffer, int offset, int count)
1111
{
1212
if (_mode != FileAccess.Read) throw new NotSupportedException();
13+
if (_streamPosition == Length) {
14+
return 0;
15+
}
1316

1417
var bytesLeft = count;
1518

@@ -51,10 +54,14 @@ private byte[] GetChunkData(int index)
5154

5255
private void SetReadStreamPosition(long newPosition)
5356
{
54-
if (newPosition < 0 || newPosition > Length)
57+
if (newPosition < 0)
5558
{
5659
throw new ArgumentOutOfRangeException();
5760
}
61+
if (newPosition >= Length) {
62+
_streamPosition = Length;
63+
return;
64+
}
5865
_streamPosition = newPosition;
5966

6067
// calculate new chunk position

0 commit comments

Comments
 (0)