Table of Contents

Class AsyncStreamCopyOptions

Namespace
Cuemon.IO
Assembly
Cuemon.IO.dll

Configuration options that is related to Stream copy operations.

public class AsyncStreamCopyOptions : AsyncDisposableOptions, IAsyncOptions, IParameterObject
Inheritance
AsyncStreamCopyOptions
Implements
Derived
Inherited Members

Examples

AsyncStreamCopyOptions configures buffer size and stream lifetime for asynchronous stream copy operations. This example creates options with BufferSize = 4096 and LeaveOpen = true, then copies UTF-8 string content from one MemoryStream to another using Decorator.Enclose(source).CopyStreamAsync(destination, options.BufferSize, ...). The copied data is read back as a string and printed to confirm "Copy me asynchronously." was transferred intact, while the source stream remains open due to LeaveOpen = true.

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

namespace Contoso.FileTransfers;

public sealed class AsyncStreamCopyOptionsExample
{
    public static async Task RunAsync()
    {
        var options = new AsyncStreamCopyOptions
        {
            BufferSize = 4096,
            LeaveOpen = true
        };

        using var source = new MemoryStream(Encoding.UTF8.GetBytes("Copy me asynchronously."));
        using var destination = new MemoryStream();

        await Decorator.Enclose(source).CopyStreamAsync(destination, options.BufferSize, changePosition: true, ct: CancellationToken.None);

        byte[] copied = await Decorator.Enclose(destination).ToByteArrayAsync(setup =>
        {
            setup.BufferSize = options.BufferSize;
            setup.LeaveOpen = options.LeaveOpen;
        });

        Console.WriteLine(Encoding.UTF8.GetString(copied));
    }
}

Constructors

AsyncStreamCopyOptions()

Initializes a new instance of the StreamCopyOptions class.

public AsyncStreamCopyOptions()

Remarks

The following table shows the initial property values for an instance of StreamCopyOptions.

PropertyInitial Value
BufferSize81920

Properties

BufferSize

Gets or sets the size of the buffer.

public int BufferSize { get; set; }

Property Value

int

The size of the buffer.

Exceptions

ArgumentOutOfRangeException

value is lower than or equal to 0.