Skip to content

Commit

Permalink
VIS-6891 Fix ReadAsync (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
amakhno authored Apr 27, 2024
1 parent 37c5b03 commit e1c63e0
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions io/StandardMeshReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,10 @@ await fileStream.ReadAsync(buffer, offset: 0, count: buffer.Length, cancellation
/// </summary>
public async Task<IOReadResult> ReadAsync(Stream stream, string sExtension, ReadOptions options, CancellationToken cancellationToken = default)
{
byte[] buffer = new byte[stream.Length];
int readBytes =
await stream.ReadAsync(buffer, offset: 0, count: buffer.Length, cancellationToken)
.ConfigureAwait(false);
if (readBytes != buffer.Length)
throw new Exception("Looks like the buffer length is not equal to the stream length");
using var memoryStream = new MemoryStream(buffer);
using var memoryStream = new MemoryStream(capacity: (int)stream.Length);
// 81_920 is a default value for the buffer size
await stream.CopyToAsync(memoryStream, 81_920, cancellationToken).ConfigureAwait(false);
memoryStream.Seek(offset: 0, loc: SeekOrigin.Begin);
return Read(memoryStream, sExtension, options);
}

Expand Down

0 comments on commit e1c63e0

Please sign in to comment.