Files
korenkonder_PD_Tool/KKdMainLib/IO/IOExtensions.cs
T
KujiKita 834442e514 Release v0.4.5.7
Some fixes and changes
2019-05-25 13:26:08 +03:00

22 lines
778 B
C#

using System.Collections.Generic;
namespace KKdMainLib.IO
{
public static class IOExtensions
{
public static string NullTerminatedASCII(this Stream stream, byte End = 0) => stream.NullTerminated(End).ToASCII();
public static string NullTerminatedUTF8 (this Stream stream, byte End = 0) => stream.NullTerminated(End).ToUTF8 ();
public static byte[] NullTerminated (this Stream stream, byte End = 0)
{
List<byte> s = new List<byte>();
while (true && stream.LongPosition > 0 && stream.LongPosition < stream.LongLength)
{
byte a = stream.ReadByte();
if (a == End) break;
else s.Add(a);
}
return s.ToArray();
}
}
}