using System.Buffers.Binary; namespace Uwaa.PNG; internal static class StreamHelper { public static int ReadBigEndianInt32(Stream stream) { Span buffer = stackalloc byte[4]; stream.Read(buffer); return BinaryPrimitives.ReadInt32BigEndian(buffer); } public static void WriteBigEndianInt32(Stream stream, int value) { Span buffer = stackalloc byte[4]; BinaryPrimitives.WriteInt32BigEndian(buffer, value); stream.Write(buffer); } public static bool TryReadHeaderBytes(Stream stream, out byte[] bytes) { bytes = new byte[8]; return stream.Read(bytes, 0, 8) == 8; } }