Files
korenkonder_PD_Tool/KKdMainLib/IO/IOExtensions.cs
T
Kuji Kitamura 8b5a939dee Release v0.4.5.8
Some fixes and changes
2019-05-26 22:22:08 +03:00

24 lines
802 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();
}
}
}