Make `HawkFile.ReadAllBytes` seek to start

fixes 633681804
This commit is contained in:
YoshiRulz 2025-01-11 22:28:16 +10:00
parent 09f8e8c544
commit c5a4ec9b81
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 6 additions and 1 deletions

View File

@ -272,9 +272,14 @@ namespace BizHawk.Common
public Stream GetStream() => _boundStream ?? throw new InvalidOperationException($"{nameof(HawkFile)}: Can't call {nameof(GetStream)}() before you've successfully bound something!");
/// <summary>attempts to read all the content from the file</summary>
public byte[] ReadAllBytes()
/// <remarks>
/// unlike <see cref="IOExtensions.IOExtensions.ReadAllBytes(Stream)"/>,
/// DOES seek to beginning unless <paramref name="fromStart"/> is <see langword="false"/>
/// </remarks>
public byte[] ReadAllBytes(bool fromStart = true)
{
var stream = GetStream();
if (fromStart) stream.Position = 0L;
using var ms = new MemoryStream((int) stream.Length);
stream.CopyTo(ms);
return ms.GetBuffer();