From 5975b48e1c12f38ea076e81fbd3414cdfe6efb16 Mon Sep 17 00:00:00 2001 From: Artem Makhno Date: Sat, 27 Apr 2024 13:11:52 +0300 Subject: [PATCH] VIS-6891 Fix ReadAsync --- io/StandardMeshReader.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/io/StandardMeshReader.cs b/io/StandardMeshReader.cs index d296fcdf..9e5bbb8e 100644 --- a/io/StandardMeshReader.cs +++ b/io/StandardMeshReader.cs @@ -134,13 +134,10 @@ await fileStream.ReadAsync(buffer, offset: 0, count: buffer.Length, cancellation /// public async Task 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); }