[Fonts] Add Stream.Write(Span<byte>) polyfill

This commit is contained in:
Jason Nelson 2024-04-01 21:43:44 -07:00 committed by BobLd
parent e01bf5e849
commit fba5b60718

View File

@ -0,0 +1,26 @@
#if NETFRAMEWORK || NETSTANDARD2_0
namespace System.IO;
using System.Buffers;
internal static class StreamExtensions
{
public static void Write(this Stream stream, ReadOnlySpan<byte> buffer)
{
var tempBuffer = ArrayPool<byte>.Shared.Rent(buffer.Length);
buffer.CopyTo(tempBuffer);
try
{
stream.Write(tempBuffer, 0, buffer.Length);
}
finally
{
ArrayPool<byte>.Shared.Return(tempBuffer);
}
}
}
#endif