Files
SabreTools/SabreTools.FileTypes/Aaru/IndexHeader.cs

43 lines
1.4 KiB
C#
Raw Normal View History

using System.IO;
using System.Text;
2020-12-08 14:53:49 -08:00
namespace SabreTools.FileTypes.Aaru
{
/// <summary>
/// Header for the index, followed by entries
/// </summary>
/// <see cref="https://github.com/aaru-dps/Aaru/blob/master/Aaru.Images/AaruFormat/Structs.cs" />
public class IndexHeader
{
/// <summary>Identifier, <see cref="BlockType.Index" /></summary>
public AaruBlockType identifier;
/// <summary>How many entries follow this header</summary>
public ushort entries;
/// <summary>CRC64-ECMA of the index</summary>
public ulong crc64;
/// <summary>
/// Read a stream as an IndexHeader
/// </summary>
/// <param name="stream">IndexHeader as a stream</param>
/// <returns>Populated IndexHeader, null on failure</returns>
public static IndexHeader Deserialize(Stream stream)
{
2024-02-28 19:19:50 -05:00
var indexHeader = new IndexHeader();
2024-02-28 21:59:13 -05:00
#if NET20 || NET35 || NET40
using (var br = new BinaryReader(stream, Encoding.Default))
#else
2024-02-28 19:19:50 -05:00
using (var br = new BinaryReader(stream, Encoding.Default, true))
2024-02-28 21:59:13 -05:00
#endif
{
indexHeader.identifier = (AaruBlockType)br.ReadUInt32();
indexHeader.entries = br.ReadUInt16();
indexHeader.crc64 = br.ReadUInt64();
}
return indexHeader;
}
}
}