26 lines
678 B
C#
26 lines
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;
|
||
|
}
|
||
|
}
|