Files
BinaryObjectScanner/BinaryObjectScanner.Models/Compression/MSZIP/FixedHuffmanCompressedBlockHeader.cs

94 lines
2.6 KiB
C#
Raw Normal View History

2022-12-15 23:51:12 -08:00
using System;
2023-03-07 16:59:14 -05:00
namespace BinaryObjectScanner.Models.Compression.MSZIP
2022-12-15 23:51:12 -08: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-01-02 15:01:24 -08:00
public class FixedHuffmanCompressedBlockHeader
2022-12-15 23:51:12 -08:00
{
#region Properties
2023-01-02 15:01:24 -08:00
/// <summary>
/// Huffman code lengths for the literal / length alphabet
/// </summary>
public uint[] LiteralLengths
2022-12-15 23:51:12 -08:00
{
get
{
// If we have cached lengths, use those
if (_literalLengths != null)
return _literalLengths;
// Otherwise, build it from scratch
2023-01-02 15:01:24 -08:00
_literalLengths = new uint[288];
2022-12-15 23:51:12 -08:00
// 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();
}
}
2023-01-02 15:01:24 -08:00
/// <summary>
/// Huffman distance codes for the literal / length alphabet
/// </summary>
public uint[] DistanceCodes
2022-12-15 23:51:12 -08:00
{
get
{
// If we have cached distances, use those
if (_distanceCodes != null)
return _distanceCodes;
// Otherwise, build it from scratch
2023-01-02 15:01:24 -08:00
_distanceCodes = new uint[30];
2022-12-15 23:51:12 -08:00
// Fixed length, 5 bits
2023-01-02 15:01:24 -08:00
for (int i = 0; i < 30; i++)
2022-12-15 23:51:12 -08:00
_distanceCodes[i] = 5;
return _distanceCodes;
}
set
{
throw new FieldAccessException();
}
}
#endregion
#region Instance Variables
/// <summary>
/// Huffman code lengths for the literal / length alphabet
/// </summary>
2023-01-02 15:01:24 -08:00
private uint[] _literalLengths = null;
2022-12-15 23:51:12 -08:00
/// <summary>
/// Huffman distance codes for the literal / length alphabet
/// </summary>
2023-01-02 15:01:24 -08:00
private uint[] _distanceCodes = null;
2022-12-15 23:51:12 -08:00
#endregion
}
}