mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-07-15 20:48:50 +08:00
[Fonts] Add Stream.Write(Span<byte>) polyfill
This commit is contained in:
parent
e01bf5e849
commit
fba5b60718
26
src/UglyToad.PdfPig.Fonts/Polyfills/StreamExtensions.cs
Normal file
26
src/UglyToad.PdfPig.Fonts/Polyfills/StreamExtensions.cs
Normal 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
|
Loading…
Reference in New Issue
Block a user