Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIS-6891 Fix ReadAsync for NetworkStream #48

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions io/StandardMeshReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
/// </summary>
public IOReadResult Read(string sFilename, ReadOptions options)
{
string? fileExtension = GetExtension(sFilename);

Check warning on line 98 in io/StandardMeshReader.cs

View workflow job for this annotation

GitHub Actions / Test geometry3sharp

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
if (fileExtension is null)
return new IOReadResult(IOCode.InvalidFilenameError, $"The extension of '{fileExtension}' is not parsed");
using FileStream fileStream = File.OpenRead(sFilename);
Expand All @@ -107,7 +107,7 @@
/// </summary>
public async Task<IOReadResult> ReadAsync(string sFilename, ReadOptions options, CancellationToken cancellationToken = default)
{
string? fileExtension = GetExtension(sFilename);

Check warning on line 110 in io/StandardMeshReader.cs

View workflow job for this annotation

GitHub Actions / Test geometry3sharp

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
if (fileExtension is null)
return new IOReadResult(IOCode.InvalidFilenameError, $"The extension of '{fileExtension}' is not parsed");
using FileStream fileStream = File.OpenRead(sFilename);
Expand All @@ -121,7 +121,7 @@
return Read(memoryStream, fileExtension, options);
}

private static string? GetExtension(string filename)

Check warning on line 124 in io/StandardMeshReader.cs

View workflow job for this annotation

GitHub Actions / Test geometry3sharp

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
string extensionWithDot = Path.GetExtension(filename);
if (extensionWithDot.Length < 2)
Expand All @@ -134,13 +134,10 @@
/// </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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем явно задавать это значение, если оно равно дефолтному?
может вызывать stream.CopyToAsync(memoryStream) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно передать cancellationToken, и там нет сигнатуры без передачи buffer size, но с токеном

memoryStream.Seek(offset: 0, loc: SeekOrigin.Begin);
return Read(memoryStream, sExtension, options);
}

Expand Down
Loading