mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace SabreTools.FileTypes.Aaru
|
|
{
|
|
/// <summary>
|
|
/// Checksum block, contains a checksum of all user data sectors
|
|
/// (except for optical discs that is 2352 bytes raw sector if available
|
|
/// </summary>
|
|
/// <see cref="https://github.com/aaru-dps/Aaru/blob/master/Aaru.Images/AaruFormat/Structs.cs" />
|
|
public class ChecksumHeader
|
|
{
|
|
/// <summary>Identifier, <see cref="BlockType.ChecksumBlock" /></summary>
|
|
public AaruBlockType identifier;
|
|
/// <summary>Length in bytes of the block</summary>
|
|
public uint length;
|
|
/// <summary>How many checksums follow</summary>
|
|
public byte entries;
|
|
|
|
/// <summary>
|
|
/// Read a stream as an ChecksumHeader
|
|
/// </summary>
|
|
/// <param name="stream">ChecksumHeader as a stream</param>
|
|
/// <returns>Populated ChecksumHeader, null on failure</returns>
|
|
public static ChecksumHeader Deserialize(Stream stream)
|
|
{
|
|
ChecksumHeader checksumHeader = new ChecksumHeader();
|
|
|
|
#if NET20 || NET35 || NET40
|
|
using (var br = new BinaryReader(stream, Encoding.Default))
|
|
#else
|
|
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
|
#endif
|
|
{
|
|
checksumHeader.identifier = (AaruBlockType)br.ReadUInt32();
|
|
checksumHeader.length = br.ReadUInt32();
|
|
checksumHeader.entries = br.ReadByte();
|
|
}
|
|
|
|
return checksumHeader;
|
|
}
|
|
}
|
|
}
|