#if NETFRAMEWORK || NETSTANDARD2_0 using System; using System.Buffers; using System.IO; namespace SharpCompress; internal static class StreamExtensions { internal static int Read(this Stream stream, Span buffer) { var temp = ArrayPool.Shared.Rent(buffer.Length); try { var read = stream.Read(temp, 0, buffer.Length); temp.AsSpan(0, read).CopyTo(buffer); return read; } finally { ArrayPool.Shared.Return(temp); } } internal static void Write(this Stream stream, ReadOnlySpan buffer) { var temp = ArrayPool.Shared.Rent(buffer.Length); buffer.CopyTo(temp); try { stream.Write(temp, 0, buffer.Length); } finally { ArrayPool.Shared.Return(temp); } } } #endif