Files

81 lines
2.7 KiB
C#
Raw Permalink Normal View History

2025-09-29 22:56:53 -04:00
namespace SabreTools.Data.Models.XZ
{
/// <summary>
/// Represents a single compressed block in the stream
/// </summary>
public class Block
{
/// <summary>
/// Size of the header
/// </summary>
/// <remarks>
/// The real header size can be calculated by the following:
/// (HeaderSize + 1) * 4
/// </remarks>
public byte HeaderSize { get; set; }
/// <summary>
/// The Block Flags field is a bit field
/// </summary>
public BlockFlags Flags { get; set; }
/// <summary>
/// Size of the compressed data
/// Present if <see cref="BlockFlags.CompressedSize"/> is set.
2025-09-29 22:56:53 -04:00
/// </summary>
/// <remarks>Stored as a variable-length integer</remarks>
2025-09-29 23:32:58 -04:00
public ulong CompressedSize { get; set; }
2025-09-29 22:56:53 -04:00
/// <summary>
/// Size of the block after decompression
/// Present if <see cref="BlockFlags.UncompressedSize"/> is set.
2025-09-29 22:56:53 -04:00
/// </summary>
/// <remarks>Stored as a variable-length integer</remarks>
2025-09-29 23:32:58 -04:00
public ulong UncompressedSize { get; set; }
2025-09-29 22:56:53 -04:00
/// <summary>
/// List of filter flags
/// </summary>
/// <remarks>
/// The number of filter flags is given by the first two
/// bits of <see cref="Flags"/>
2025-09-29 22:56:53 -04:00
/// </remarks>
public FilterFlag[] FilterFlags { get; set; } = [];
2025-09-29 22:56:53 -04:00
/// <summary>
/// This field contains as many null byte as it is needed to make
/// the Block Header have the size specified in Block Header Size.
/// </summary>
public byte[] HeaderPadding { get; set; } = [];
2025-09-29 22:56:53 -04:00
/// <summary>
/// The CRC32 is calculated over everything in the Block Header
/// field except the CRC32 field itself. It is stored as an
/// unsigned 32-bit little endian integer.
2025-09-29 22:56:53 -04:00
/// </summary>
public uint Crc32 { get; set; }
/// <summary>
/// The format of Compressed Data depends on Block Flags and List
/// of Filter Flags
/// </summary>
public byte[] CompressedData { get; set; } = [];
2025-09-29 22:56:53 -04:00
/// <summary>
/// Block Padding MUST contain 0-3 null bytes to make the size of
/// the Block a multiple of four bytes. This can be needed when
/// the size of Compressed Data is not a multiple of four.
/// </summary>
public byte[] BlockPadding { get; set; } = [];
2025-09-29 22:56:53 -04:00
/// <summary>
/// The type and size of the Check field depends on which bits
/// are set in the Stream Flags field.
///
2025-09-29 22:56:53 -04:00
/// The Check, when used, is calculated from the original
/// uncompressed data.
/// </summary>
public byte[] Check { get; set; } = [];
2025-09-29 22:56:53 -04:00
}
}