Skip to content

Commit

Permalink
Merge pull request #819 from TwanVanDongen/master
Browse files Browse the repository at this point in the history
Support added for TAR LZW compression (Unix 'compress' resulting in .…
  • Loading branch information
adamhathcock authored Mar 25, 2024
2 parents bcb61ee + f2b0368 commit fb73d8c
Show file tree
Hide file tree
Showing 8 changed files with 688 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/SharpCompress/Common/CompressionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public enum CompressionType
Xz,
Unknown,
Deflate64,
Shrink
Shrink,
Lzw
}
65 changes: 65 additions & 0 deletions src/SharpCompress/Compressors/Lzw/LzwConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace SharpCompress.Compressors.Lzw
{
/// <summary>
/// This class contains constants used for LZW
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Naming",
"CA1707:Identifiers should not contain underscores",
Justification = "kept for backwards compatibility"
)]
public sealed class LzwConstants
{
/// <summary>
/// Magic number found at start of LZW header: 0x1f 0x9d
/// </summary>
public const int MAGIC = 0x1f9d;

/// <summary>
/// Maximum number of bits per code
/// </summary>
public const int MAX_BITS = 16;

/* 3rd header byte:
* bit 0..4 Number of compression bits
* bit 5 Extended header
* bit 6 Free
* bit 7 Block mode
*/

/// <summary>
/// Mask for 'number of compression bits'
/// </summary>
public const int BIT_MASK = 0x1f;

/// <summary>
/// Indicates the presence of a fourth header byte
/// </summary>
public const int EXTENDED_MASK = 0x20;

//public const int FREE_MASK = 0x40;

/// <summary>
/// Reserved bits
/// </summary>
public const int RESERVED_MASK = 0x60;

/// <summary>
/// Block compression: if table is full and compression rate is dropping,
/// clear the dictionary.
/// </summary>
public const int BLOCK_MODE_MASK = 0x80;

/// <summary>
/// LZW file header size (in bytes)
/// </summary>
public const int HDR_SIZE = 3;

/// <summary>
/// Initial number of bits per code
/// </summary>
public const int INIT_BITS = 9;

private LzwConstants() { }
}
}
Loading

0 comments on commit fb73d8c

Please sign in to comment.