1
0
mirror of https://github.com/chylex/.NET-Community-Toolkit.git synced 2024-11-25 01:42:46 +01:00
.NET-Community-Toolkit/CommunityToolkit.HighPerformance/Streams/IMemoryOwnerStream{TSource}.cs
2021-11-01 20:46:46 +01:00

42 lines
1.4 KiB
C#

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Buffers;
using System.IO;
namespace CommunityToolkit.HighPerformance.Streams;
/// <summary>
/// A <see cref="Stream"/> implementation wrapping an <see cref="IMemoryOwner{T}"/> of <see cref="byte"/> instance.
/// </summary>
/// <typeparam name="TSource">The type of source to use for the underlying data.</typeparam>
internal sealed class IMemoryOwnerStream<TSource> : MemoryStream<TSource>
where TSource : struct, ISpanOwner
{
/// <summary>
/// The <see cref="IDisposable"/> instance currently in use.
/// </summary>
private readonly IDisposable disposable;
/// <summary>
/// Initializes a new instance of the <see cref="IMemoryOwnerStream{TSource}"/> class.
/// </summary>
/// <param name="source">The input <typeparamref name="TSource"/> instance to use.</param>
/// <param name="disposable">The <see cref="IDisposable"/> instance currently in use.</param>
public IMemoryOwnerStream(TSource source, IDisposable disposable)
: base(source, false)
{
this.disposable = disposable;
}
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
this.disposable.Dispose();
}
}