0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-10-13 23:10:23 +03:00

improvements

This commit is contained in:
bird_egop
2025-10-05 18:17:18 +03:00
parent c1ea70efe0
commit a774db37a6
17 changed files with 472 additions and 128 deletions

View File

@@ -5,7 +5,7 @@ namespace Common;
public static class Extensions
{
public static int ReadInt32LittleEndian(this FileStream fs)
public static int ReadInt32LittleEndian(this Stream fs)
{
Span<byte> buf = stackalloc byte[4];
fs.ReadExactly(buf);
@@ -13,7 +13,7 @@ public static class Extensions
return BinaryPrimitives.ReadInt32LittleEndian(buf);
}
public static uint ReadUInt32LittleEndian(this FileStream fs)
public static uint ReadUInt32LittleEndian(this Stream fs)
{
Span<byte> buf = stackalloc byte[4];
fs.ReadExactly(buf);
@@ -21,7 +21,7 @@ public static class Extensions
return BinaryPrimitives.ReadUInt32LittleEndian(buf);
}
public static float ReadFloatLittleEndian(this FileStream fs)
public static float ReadFloatLittleEndian(this Stream fs)
{
Span<byte> buf = stackalloc byte[4];
fs.ReadExactly(buf);
@@ -29,7 +29,7 @@ public static class Extensions
return BinaryPrimitives.ReadSingleLittleEndian(buf);
}
public static string ReadNullTerminatedString(this FileStream fs)
public static string ReadNullTerminatedString(this Stream fs)
{
var sb = new StringBuilder();
@@ -47,7 +47,25 @@ public static class Extensions
return sb.ToString();
}
public static string ReadLengthPrefixedString(this FileStream fs)
public static string ReadNullTerminated1251String(this Stream fs)
{
var sb = new StringBuilder();
while (true)
{
var b = (byte)fs.ReadByte();
if (b == 0)
{
break;
}
sb.Append(Encoding.GetEncoding("windows-1251").GetString([b]));
}
return sb.ToString();
}
public static string ReadLengthPrefixedString(this Stream fs)
{
var len = fs.ReadInt32LittleEndian();