Files
SabreTools.Models/Compression/MSZIP/FixedCompressedDataHeader.cs

94 lines
2.7 KiB
C#
Raw Normal View History

2023-09-04 00:11:04 -04:00
using System;
2023-09-04 00:12:49 -04:00
namespace SabreTools.Models.Compression.MSZIP
2023-09-04 00:11:04 -04:00
{
/// <summary>
/// Compression with fixed Huffman codes (BTYPE=01)
/// </summary>
/// <see href="https://interoperability.blob.core.windows.net/files/MS-MCI/%5bMS-MCI%5d.pdf"/>
/// <see href="https://www.rfc-editor.org/rfc/rfc1951"/>
2023-09-22 15:32:19 -04:00
public class FixedCompressedDataHeader : CompressedDataHeader
2023-09-04 00:11:04 -04:00
{
#region Properties
/// <summary>
/// Huffman code lengths for the literal / length alphabet
/// </summary>
2023-09-22 11:54:48 -04:00
public override uint[]? LiteralLengths
2023-09-04 00:11:04 -04:00
{
get
{
// If we have cached lengths, use those
if (_literalLengths != null)
return _literalLengths;
// Otherwise, build it from scratch
_literalLengths = new uint[288];
// Literal Value 0 - 143, 8 bits
for (int i = 0; i < 144; i++)
_literalLengths[i] = 8;
// Literal Value 144 - 255, 9 bits
for (int i = 144; i < 256; i++)
_literalLengths[i] = 9;
// Literal Value 256 - 279, 7 bits
for (int i = 256; i < 280; i++)
_literalLengths[i] = 7;
// Literal Value 280 - 287, 8 bits
for (int i = 280; i < 288; i++)
_literalLengths[i] = 8;
return _literalLengths;
}
set
{
throw new FieldAccessException();
}
}
/// <summary>
/// Huffman distance codes for the literal / length alphabet
/// </summary>
2023-09-22 11:54:48 -04:00
public override uint[]? DistanceCodes
2023-09-04 00:11:04 -04:00
{
get
{
// If we have cached distances, use those
if (_distanceCodes != null)
return _distanceCodes;
// Otherwise, build it from scratch
_distanceCodes = new uint[30];
// Fixed length, 5 bits
for (int i = 0; i < 30; i++)
_distanceCodes[i] = 5;
return _distanceCodes;
}
set
{
throw new FieldAccessException();
}
}
#endregion
#region Instance Variables
/// <summary>
/// Huffman code lengths for the literal / length alphabet
/// </summary>
2023-09-04 21:14:41 -04:00
private uint[]? _literalLengths = null;
2023-09-04 00:11:04 -04:00
/// <summary>
/// Huffman distance codes for the literal / length alphabet
/// </summary>
2023-09-04 21:14:41 -04:00
private uint[]? _distanceCodes = null;
2023-09-04 00:11:04 -04:00
#endregion
}
}