PNG/StreamHelper.cs
2024-11-03 21:34:26 +00:00

26 lines
No EOL
678 B
C#

using System.Buffers.Binary;
namespace Uwaa.PNG;
internal static class StreamHelper
{
public static int ReadBigEndianInt32(Stream stream)
{
Span<byte> buffer = stackalloc byte[4];
stream.Read(buffer);
return BinaryPrimitives.ReadInt32BigEndian(buffer);
}
public static void WriteBigEndianInt32(Stream stream, int value)
{
Span<byte> 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;
}
}