Skip to content

Commit

Permalink
fixes scenario when reading from buffered stream (it could read less … (
Browse files Browse the repository at this point in the history
#202)

* fixes scenario when reading from buffered stream (it could read less than record byte count)
  • Loading branch information
andreykorolev authored Oct 24, 2023
1 parent d82c449 commit cb514be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/DbfDataReader/DbfDataReader.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>DbfDataReader is a small fast .Net Core library for reading dBase, xBase, Clipper and FoxPro database files</Description>
Expand Down
11 changes: 10 additions & 1 deletion src/DbfDataReader/DbfRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ public bool Read(Stream stream)

try
{
stream.Read(_buffer, 0, _recordLength);
var read = stream.Read(_buffer, 0, _recordLength);
if (read <= 0)
return false;
while (read < _recordLength)
{
var r = stream.Read(_buffer, read, _recordLength - read);
if (r == 0)
return false;
read += r;
}
var span = new ReadOnlySpan<byte>(_buffer);

var value = span[0];
Expand Down

0 comments on commit cb514be

Please sign in to comment.