Files
sbox-public/engine/Sandbox.System/Extend/StreamExtensions.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

27 lines
704 B
C#

using System.IO;
using System.Runtime.InteropServices;
namespace Sandbox;
public static partial class SandboxSystemExtensions
{
/// <summary>
/// Read a null terminated string from the stream, at given offset.
/// </summary>
/// <param name="stream">The stream to read from.</param>
/// <param name="offset">Offset where to start reading, from the beginning of the stream.</param>
public static string ReadNullTerminatedString( this Stream stream, long offset )
{
stream.Seek( offset, SeekOrigin.Begin );
int b;
List<byte> bytes = new List<byte>();
while ( (b = stream.ReadByte()) != 0x00 )
{
bytes.Add( (byte)b );
}
return Encoding.UTF8.GetString( bytes.ToArray() );
}
}