1
0
mirror of https://github.com/chylex/.NET-Community-Toolkit.git synced 2025-08-18 11:31:45 +02:00
Files
.github
CommunityToolkit.Common
CommunityToolkit.Diagnostics
CommunityToolkit.HighPerformance
Attributes
Buffers
Enumerables
Extensions
Helpers
Memory
Properties
Streams
Sources
IBufferWriterStream{TWriter}.Memory.cs
IBufferWriterStream{TWriter}.cs
IMemoryOwnerStream{TSource}.cs
MemoryStream.ThrowExceptions.cs
MemoryStream.Validate.cs
MemoryStream.cs
MemoryStream{TSource}.Memory.cs
MemoryStream{TSource}.cs
Box{T}.cs
CommunityToolkit.HighPerformance.csproj
NullableReadOnlyRef{T}.cs
NullableRef{T}.cs
ReadOnlyRef{T}.cs
Ref{T}.cs
CommunityToolkit.Mvvm
CommunityToolkit.Mvvm.SourceGenerators
build
tests
.editorconfig
.git-blame-ignore-revs
.gitattributes
.gitignore
.runsettings
CODE_OF_CONDUCT.md
Contributing.md
Directory.Build.props
Directory.Build.targets
License.md
README.md
ThirdPartyNotices.txt
azure-pipelines.yml
dotnet Community Toolkit.sln
toolkit.snk
version.json
2022-01-01 17:02:31 +01:00

75 lines
1.9 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.
#if NETSTANDARD2_1_OR_GREATER
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace CommunityToolkit.HighPerformance.Streams;
/// <inheritdoc/>
partial class IBufferWriterStream<TWriter>
{
/// <inheritdoc/>
public override void CopyTo(Stream destination, int bufferSize)
{
throw MemoryStream.GetNotSupportedException();
}
/// <inheritdoc/>
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
{
throw MemoryStream.GetNotSupportedException();
}
/// <inheritdoc/>
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
return new(Task.FromCanceled(cancellationToken));
}
try
{
Write(buffer.Span);
return default;
}
catch (OperationCanceledException e)
{
return new(Task.FromCanceled(e.CancellationToken));
}
catch (Exception e)
{
return new(Task.FromException(e));
}
}
/// <inheritdoc/>
public override int Read(Span<byte> buffer)
{
throw MemoryStream.GetNotSupportedException();
}
/// <inheritdoc/>
public override void Write(ReadOnlySpan<byte> buffer)
{
MemoryStream.ValidateDisposed(this.disposed);
Span<byte> destination = this.bufferWriter.GetSpan(buffer.Length);
if (!buffer.TryCopyTo(destination))
{
MemoryStream.ThrowArgumentExceptionForEndOfStreamOnWrite();
}
this.bufferWriter.Advance(buffer.Length);
}
}
#endif