Change Yaz0 method ReadFile to FromBytes

This commit is contained in:
Chev 2021-01-16 22:51:04 -08:00
parent f19f94f459
commit 7aa85c437b

View file

@ -32,14 +32,12 @@ namespace BOTWToolset.IO.Yaz0
/// </summary> /// </summary>
/// <param name="file">The file (full path) to read.</param> /// <param name="file">The file (full path) to read.</param>
/// <returns><see cref="Yaz0"/> containing the file's data.</returns> /// <returns><see cref="Yaz0"/> containing the file's data.</returns>
public static Yaz0 ReadFile(string file) public static Yaz0 FromBytes(byte[] bytes)
{
if (File.Exists(file))
{ {
Yaz0 y = new Yaz0(); Yaz0 y = new Yaz0();
// Use big-endian // Use big-endian
using (var r = new BinaryReaderBig(File.Open(file, FileMode.Open))) using (var r = new BinaryReaderBig(new MemoryStream(bytes)))
{ {
y.Magic = new string(r.ReadChars(4)); y.Magic = new string(r.ReadChars(4));
if (y.Magic != "Yaz0") if (y.Magic != "Yaz0")
@ -57,11 +55,6 @@ namespace BOTWToolset.IO.Yaz0
return y; return y;
} }
else
{
throw new FileNotFoundException("Cannot find Yaz0 file to read.");
}
}
/// <summary> /// <summary>
/// Decompresses a Yaz0-encoded array of bytes. /// Decompresses a Yaz0-encoded array of bytes.