System Library Common Framework
Search Results for

    *.Benchmark*,*.Tests*,*.ApiTests*,*.BaseTest*,DelegateJsonConverter,CalleeCancelledRequestException,ClientResponse,ContentType,OutputCachePolicy
    Show / Hide Table of Contents Show / Hide Table of Contents
    NamespaceSystemLibrary.Common.Framework.Extensions SystemLibrary.Common.Framework.Json.dll

    Extensions for streams like reading content as json directly into class through JsonAsync()

    StreamExtensions

    public static class StreamExtensions

    Inheritance
    object
    StreamExtensions
    Examples
    Arguments
    X

    Methods

    Reading a Stream async as JsonData converting it into a class T

    Used for instance when you read the content of a HttpResponse and directly converting it into T instead of storing as string first

    public static Task<T> JsonAsync<T>(this Stream stream, JsonSerializerOptions options = null, CancellationToken cancellationToken = default)

    X
    using (var contentStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
       return await contentStream.JsonAsync<T>(jsonSerializerOptions).ConfigureAwait(false);
    X
    Generic types
    Name Description
    T
    Methods arguments
    Type Name Description
    Stream stream
    JsonSerializerOptions options
    CancellationToken cancellationToken
    X
    Type Description
    Task<T>

    T or default

    Reads a stream and hashing its content as MD5

    Remarks
    X

    If data is larger than ~200 bytes then .ToSha1Hash() is faster

    public static string ToMD5Hash(this Stream stream)

    X
    var fileStream = new FileStream(@"C:\file.txt", FileMode.Open);
    var hash = fileStream.ToMD5Hash();
    X
    Methods arguments
    Type Name Description
    Stream stream
    X
    Type Description
    string

    Md5 hash or null if unreadable stream

    Reads a stream and hashing its content as MD5

    Remarks
    X

    If data is larger than ~200 bytes then .ToSha1Hash() is faster

    public static Task<string> ToMD5HashAsync(this Stream stream)

    X
    var fileStream = new FileStream(@"C:\file.txt", FileMode.Open);
    var hash = fileStream.ToMD5HashAsync().Result;
    X
    Methods arguments
    Type Name Description
    Stream stream
    X
    Type Description
    Task<string>

    Md5 hash or null if unreadable stream

    Reads a stream and hashing its content as Sha1

    Remarks
    X

    If data is smaller than ~200 bytes then .ToMD5Hash() is faster

    public static string ToSha1Hash(this Stream stream)

    X
    var fileStream = new FileStream(@"C:\file.txt", FileMode.Open);
    var hash = fileStream.ToSha1Hash();
    X
    Methods arguments
    Type Name Description
    Stream stream
    X
    Type Description
    string

    Sha1 hash or null if unreadable stream

    Reads a stream and hashing its content as Sha1

    Remarks
    X

    If data is smaller than ~200 bytes then .ToMD5Hash() is faster

    public static Task<string> ToSha1HashAsync(this Stream stream)

    X
    var fileStream = new FileStream(@"C:\file.txt", FileMode.Open);
    var hash = fileStream.ToSha1HashAsync().Result;
    X
    Methods arguments
    Type Name Description
    Stream stream
    X
    Type Description
    Task<string>

    Sha1 hash or null if unreadable stream

    Reads a stream and hashing its content as Sha256

    public static string ToSha256Hash(this Stream stream)

    X
    var fileStream = new FileStream(@"C:\file.txt", FileMode.Open);
    var hash = fileStream.ToSha256Hash();
    X
    Methods arguments
    Type Name Description
    Stream stream
    X
    Type Description
    string

    Sha256 hash or null if unreadable stream

    Reads a stream and hashing its content as Sha256

    public static Task<string> ToSha256HashAsync(this Stream stream)

    X
    var fileStream = new FileStream(@"C:\file.txt", FileMode.Open);
    var hash = fileStream.ToSha256HashAsync().Result;
    X
    Methods arguments
    Type Name Description
    Stream stream
    X
    Type Description
    Task<string>

    Sha256 hash or null if unreadable stream

    }

    In This Article
    Package: nuget
    Source: github
    Website: System Library Common Framework