mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-09 02:16:55 +00:00
GZIP model cleanup
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
namespace SabreTools.Data.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public sealed class Archive
|
||||
{
|
||||
/// <summary>
|
||||
/// Header including optional fields
|
||||
/// </summary>
|
||||
public Header? Header { get; set; }
|
||||
public Header Header { get; set; }
|
||||
|
||||
// Compressed blocks live here
|
||||
|
||||
/// <summary>
|
||||
/// Trailer
|
||||
/// </summary>
|
||||
public Trailer? Trailer { get; set; }
|
||||
public Trailer Trailer { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace SabreTools.Data.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public static class Constants
|
||||
{
|
||||
public const byte ID1 = 0x1F;
|
||||
@@ -11,4 +11,4 @@ namespace SabreTools.Data.Models.GZIP
|
||||
|
||||
public static readonly byte[] TorrentGZHeader = [0x1F, 0x8B, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
|
||||
namespace SabreTools.Data.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public enum CompressionMethod : byte
|
||||
{
|
||||
RESERVED0 = 0,
|
||||
@@ -17,7 +17,7 @@ namespace SabreTools.Data.Models.GZIP
|
||||
Deflate = 8,
|
||||
}
|
||||
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
[Flags]
|
||||
public enum ExtraFlags : byte
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace SabreTools.Data.Models.GZIP
|
||||
FastestAlgorithm = 0x04,
|
||||
}
|
||||
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
[Flags]
|
||||
public enum Flags : byte
|
||||
{
|
||||
@@ -66,7 +66,7 @@ namespace SabreTools.Data.Models.GZIP
|
||||
RESERVED7 = 0x80,
|
||||
}
|
||||
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public enum OperatingSystem : byte
|
||||
{
|
||||
/// <summary>
|
||||
@@ -144,4 +144,4 @@ namespace SabreTools.Data.Models.GZIP
|
||||
/// </summary>
|
||||
Unknown = 255,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace SabreTools.Data.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public sealed class Header
|
||||
{
|
||||
/// <summary>
|
||||
@@ -25,7 +25,7 @@ namespace SabreTools.Data.Models.GZIP
|
||||
|
||||
/// <summary>
|
||||
/// Modification TIME
|
||||
///
|
||||
///
|
||||
/// This gives the most recent modification time of the original
|
||||
/// file being compressed. The time is in Unix format, i.e.,
|
||||
/// seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this
|
||||
@@ -44,7 +44,7 @@ namespace SabreTools.Data.Models.GZIP
|
||||
|
||||
/// <summary>
|
||||
/// Operating System
|
||||
///
|
||||
///
|
||||
/// This identifies the type of file system on which compression
|
||||
/// took place. This may be useful in determining end-of-line
|
||||
/// convention for text files.
|
||||
@@ -53,7 +53,7 @@ namespace SabreTools.Data.Models.GZIP
|
||||
|
||||
/// <summary>
|
||||
/// eXtra LENgth
|
||||
///
|
||||
///
|
||||
/// If FLG.FEXTRA is set, this gives the length of the optional
|
||||
/// extra field.
|
||||
/// </summary>
|
||||
@@ -61,7 +61,7 @@ namespace SabreTools.Data.Models.GZIP
|
||||
|
||||
/// <summary>
|
||||
/// Extra field
|
||||
///
|
||||
///
|
||||
/// If the FLG.FEXTRA bit is set, an "extra field" is present in
|
||||
/// the header, with total length XLEN bytes. It consists of a
|
||||
/// series of subfields, each of the form <see cref="ExtraFieldData"/>.
|
||||
@@ -71,7 +71,7 @@ namespace SabreTools.Data.Models.GZIP
|
||||
|
||||
/// <summary>
|
||||
/// Extra field
|
||||
///
|
||||
///
|
||||
/// If the FLG.FEXTRA bit is set, an "extra field" is present in
|
||||
/// the header, with total length XLEN bytes. It consists of a
|
||||
/// series of subfields, each of the form <see cref="ExtraFieldData"/>.
|
||||
@@ -96,4 +96,4 @@ namespace SabreTools.Data.Models.GZIP
|
||||
/// </summary>
|
||||
public ushort? CRC16 { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace SabreTools.Data.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public sealed class Trailer
|
||||
{
|
||||
/// <summary>
|
||||
/// CRC-32
|
||||
///
|
||||
///
|
||||
/// This contains a Cyclic Redundancy Check value of the
|
||||
/// uncompressed data computed according to CRC-32 algorithm
|
||||
/// used in the ISO 3309 standard and in section 8.1.1.6.2 of
|
||||
@@ -17,10 +17,10 @@ namespace SabreTools.Data.Models.GZIP
|
||||
|
||||
/// <summary>
|
||||
/// Input SIZE
|
||||
///
|
||||
///
|
||||
/// This contains the size of the original (uncompressed) input
|
||||
/// data modulo 2^32.
|
||||
/// </summary>
|
||||
public uint InputSize { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,17 +22,10 @@ namespace SabreTools.Serialization.Wrappers
|
||||
Print(builder, Model.Trailer);
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, Header? header)
|
||||
private static void Print(StringBuilder builder, Header header)
|
||||
{
|
||||
builder.AppendLine(" Header:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (header == null)
|
||||
{
|
||||
builder.AppendLine(" No header");
|
||||
builder.AppendLine();
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendLine(header.ID1, " ID1");
|
||||
builder.AppendLine(header.ID2, " ID1");
|
||||
builder.AppendLine($" Compression method: {header.CompressionMethod} (0x{(byte)header.CompressionMethod:X2})");
|
||||
@@ -71,17 +64,10 @@ namespace SabreTools.Serialization.Wrappers
|
||||
}
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, Trailer? trailer)
|
||||
private static void Print(StringBuilder builder, Trailer trailer)
|
||||
{
|
||||
builder.AppendLine(" Trailer:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (trailer == null)
|
||||
{
|
||||
builder.AppendLine(" No trailer");
|
||||
builder.AppendLine();
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendLine(trailer.CRC32, " CRC-32");
|
||||
builder.AppendLine(trailer.InputSize, " Input size");
|
||||
builder.AppendLine();
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
get
|
||||
{
|
||||
// Only valid for Torrent GZip
|
||||
if (Header == null || !IsTorrentGZip)
|
||||
if (!IsTorrentGZip)
|
||||
return null;
|
||||
|
||||
// CRC-32 is the second packed field
|
||||
@@ -42,7 +42,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
get
|
||||
{
|
||||
// Only valid for Torrent GZip
|
||||
if (Header == null || !IsTorrentGZip)
|
||||
if (!IsTorrentGZip)
|
||||
return null;
|
||||
|
||||
// MD5 is the first packed field
|
||||
@@ -60,7 +60,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
get
|
||||
{
|
||||
// Only valid for Torrent GZip
|
||||
if (Header == null || !IsTorrentGZip)
|
||||
if (!IsTorrentGZip)
|
||||
return 0;
|
||||
|
||||
// MD5 is the first packed field
|
||||
@@ -80,9 +80,6 @@ namespace SabreTools.Serialization.Wrappers
|
||||
if (_dataOffset > -1)
|
||||
return _dataOffset;
|
||||
|
||||
if (Header == null)
|
||||
return -1;
|
||||
|
||||
// Minimum offset is 10 bytes:
|
||||
// - ID1 (1)
|
||||
// - ID2 (1)
|
||||
@@ -107,7 +104,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Archive.Header"/>
|
||||
public Header? Header => Model.Header;
|
||||
public Header Header => Model.Header;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the archive is in the standard
|
||||
@@ -119,10 +116,6 @@ namespace SabreTools.Serialization.Wrappers
|
||||
{
|
||||
get
|
||||
{
|
||||
// If the header is invalid
|
||||
if (Header == null)
|
||||
return false;
|
||||
|
||||
// Torrent GZip uses normal deflate, not GZIP deflate
|
||||
if (Header.CompressionMethod != CompressionMethod.Deflate)
|
||||
return false;
|
||||
@@ -155,7 +148,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Archive.Trailer"/>
|
||||
public Trailer? Trailer => Model.Trailer;
|
||||
public Trailer Trailer => Model.Trailer;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user