Table of Contents

AsyncStreamEncodingOptions Class

Definition

Namespace
Cuemon.IO
Assemblies
Cuemon.IO.dll
Source
src/Cuemon.IO/AsyncStreamEncodingOptions.cs

Configuration options for Stream.

public class AsyncStreamEncodingOptions : AsyncDisposableOptions, IAsyncOptions, IParameterObject, IEncodingOptions
Inheritance
object
AsyncStreamEncodingOptions
Implements
Derived
Inherited Members

Examples

AsyncStreamEncodingOptions configures encoding, preamble handling, and stream lifetime when reading text from a stream asynchronously. This example creates options with Encoding.UTF8, PreambleSequence.Remove to strip the BOM from output, and LeaveOpen = false, then creates a MemoryStream with UTF-8 encoded text and reads the content using a StreamReader with the configured encoding. Console output displays "Hello, AsyncStreamEncodingOptions!", confirming the text was read correctly with the configured encoding settings.

using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Cuemon.IO;
using Cuemon.Text;

namespace MyApp.Examples;

public class AsyncStreamEncodingOptionsExample
{
    public static async Task Main()
    {
        var options = new AsyncStreamEncodingOptions
        {
            Encoding = Encoding.UTF8,
            Preamble = PreambleSequence.Remove,
            LeaveOpen = false
        };

        string text = "Hello, AsyncStreamEncodingOptions!";
        byte[] bytes = Encoding.UTF8.GetBytes(text);

        using var stream = new MemoryStream(bytes);
        using var reader = new StreamReader(stream, options.Encoding);

        string result = await reader.ReadToEndAsync();
        Console.WriteLine(result);

        // Output:
        // Hello, AsyncStreamEncodingOptions!

}
}

Constructors

Name Description
AsyncStreamEncodingOptions()

Initializes a new instance of the AsyncStreamEncodingOptions class.

Properties

Name Description
Encoding

Gets or sets the character encoding to use for the operation.

Preamble

Gets or sets the action to take in regards to encoding related preamble sequences.