Table of Contents

Class StreamExtensions

Namespace
Songhay.Extensions
Assembly
SonghayCore.dll

Extensions of Stream

public static class StreamExtensions
Inheritance
StreamExtensions
Inherited Members

Remarks

The stream-reader methods in this class work well with Microsoft.AspNetCore.Http.HttpRequest.Body.

Methods

ReadStreamAsStringAsync(Stream?)

Reads the specified Stream, optimistically calling ReadToEndAsync()

public static Task<string?> ReadStreamAsStringAsync(this Stream? stream)

Parameters

stream Stream

the Stream

Returns

Task<string>

Remarks

This member is likely more memory intensive than we should see when we look at the Microsoft source code for ReadAsStringAsync().

ReadStreamIntoDictionaryAsync(Stream, ILogger)

Reads the specified Stream with ReadStreamAsStringAsync(Stream?), expecting a string that can be deserialized as a Dictionary<TKey, TValue> where TKey and TValue are string or the specified ILogger will record an exception.

public static Task<Dictionary<string, string?>?> ReadStreamIntoDictionaryAsync(this Stream stream, ILogger logger)

Parameters

stream Stream

the Stream

logger ILogger

The logger.

Returns

Task<Dictionary<string, string>>

ReadStreamIntoJsonElementAsync(Stream, ILogger)

Reads the specified Stream with ReadStreamAsStringAsync(Stream?), expecting a string that can be parsed into a JsonElement or the specified ILogger will record an exception.

public static Task<JsonElement> ReadStreamIntoJsonElementAsync(this Stream stream, ILogger logger)

Parameters

stream Stream

the Stream

logger ILogger

The logger.

Returns

Task<JsonElement>