From 0c4df26ed0fa83f53cf56f374d36b6e89195ef9a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 16 Jun 2013 05:07:25 +1200 Subject: [PATCH] Add Stream.ReadASCIIZ for d2k. --- OpenRA.FileFormats/StreamExts.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/OpenRA.FileFormats/StreamExts.cs b/OpenRA.FileFormats/StreamExts.cs index 0604cc25f6..e2bef625f0 100755 --- a/OpenRA.FileFormats/StreamExts.cs +++ b/OpenRA.FileFormats/StreamExts.cs @@ -79,6 +79,25 @@ namespace OpenRA return new string(Encoding.ASCII.GetChars(s.ReadBytes(length))); } + public static string ReadASCIIZ(this Stream s) + { + var bytes = new List(); + var buf = new byte[1]; + + for (;;) + { + if (s.Read(buf, 0, 1) < 1) + throw new EndOfStreamException(); + + if (buf[0] == 0) + break; + + bytes.Add(buf[0]); + } + + return new string(Encoding.ASCII.GetChars(bytes.ToArray())); + } + public static string ReadAllText(this Stream s) { using (s)