mirror of
https://github.com/SabreTools/SabreTools.Models.git
synced 2026-09-23 23:25:35 +00:00
Add GZIP models
This commit is contained in:
18
SabreTools.Models/GZIP/Archive.cs
Normal file
18
SabreTools.Models/GZIP/Archive.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace SabreTools.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public sealed class Archive
|
||||
{
|
||||
/// <summary>
|
||||
/// Header including optional fields
|
||||
/// </summary>
|
||||
public Header? Header;
|
||||
|
||||
// Compressed blocks live here
|
||||
|
||||
/// <summary>
|
||||
/// Trailer
|
||||
/// </summary>
|
||||
public Trailer? Trailer;
|
||||
}
|
||||
}
|
||||
10
SabreTools.Models/GZIP/Constants.cs
Normal file
10
SabreTools.Models/GZIP/Constants.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace SabreTools.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public static class Constants
|
||||
{
|
||||
public const byte ID1 = 0x1F;
|
||||
|
||||
public const byte ID2 = 0x8B;
|
||||
}
|
||||
}
|
||||
147
SabreTools.Models/GZIP/Enums.cs
Normal file
147
SabreTools.Models/GZIP/Enums.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
|
||||
namespace SabreTools.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public enum CompressionMethod : byte
|
||||
{
|
||||
RESERVED0 = 0,
|
||||
RESERVED1 = 1,
|
||||
RESERVED2 = 2,
|
||||
RESERVED3 = 3,
|
||||
RESERVED4 = 4,
|
||||
RESERVED5 = 5,
|
||||
RESERVED6 = 6,
|
||||
RESERVED7 = 7,
|
||||
|
||||
Deflate = 8,
|
||||
}
|
||||
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
[Flags]
|
||||
public enum ExtraFlags : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Compressor used maximum compression, slowest algorithm
|
||||
/// </summary>
|
||||
MaximumCompression = 0x02,
|
||||
|
||||
/// <summary>
|
||||
/// Compressor used fastest algorithm
|
||||
/// </summary>
|
||||
FastestAlgorithm = 0x04,
|
||||
}
|
||||
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
[Flags]
|
||||
public enum Flags : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// The file is probably ASCII text
|
||||
/// </summary>
|
||||
FTEXT = 0x01,
|
||||
|
||||
/// <summary>
|
||||
/// CRC-16 for the gzip header is present
|
||||
/// </summary>
|
||||
FHCRC = 0x02,
|
||||
|
||||
/// <summary>
|
||||
/// Optional extra fields are present
|
||||
/// </summary>
|
||||
FEXTRA = 0x04,
|
||||
|
||||
/// <summary>
|
||||
/// Original filename is present
|
||||
/// </summary>
|
||||
FNAME = 0x08,
|
||||
|
||||
/// <summary>
|
||||
/// Zero-terminated file comment is present
|
||||
/// </summary>
|
||||
FCOMMENT = 0x10,
|
||||
|
||||
RESERVED5 = 0x20,
|
||||
RESERVED6 = 0x40,
|
||||
RESERVED7 = 0x80,
|
||||
}
|
||||
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public enum OperatingSystem : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// FAT filesystem (MS-DOS, OS/2, NT/Win32)
|
||||
/// </summary>
|
||||
FAT = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Amiga
|
||||
/// </summary>
|
||||
Amiga = 1,
|
||||
|
||||
/// <summary>
|
||||
/// VMS (or OpenVMS)
|
||||
/// </summary>
|
||||
VMS = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Unix
|
||||
/// </summary>
|
||||
Unix = 3,
|
||||
|
||||
/// <summary>
|
||||
/// VM/CMS
|
||||
/// </summary>
|
||||
VMCMS = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Atari TOS
|
||||
/// </summary>
|
||||
AtariTOS = 5,
|
||||
|
||||
/// <summary>
|
||||
/// HPFS filesystem (OS/2, NT)
|
||||
/// </summary>
|
||||
HPFS = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Macintosh
|
||||
/// </summary>
|
||||
Macintosh = 7,
|
||||
|
||||
/// <summary>
|
||||
/// Z-System
|
||||
/// </summary>
|
||||
ZSystem = 8,
|
||||
|
||||
/// <summary>
|
||||
/// CP/M
|
||||
/// </summary>
|
||||
CPM = 9,
|
||||
|
||||
/// <summary>
|
||||
/// TOPS-20
|
||||
/// </summary>
|
||||
TOPS20 = 10,
|
||||
|
||||
/// <summary>
|
||||
/// NTFS filesystem (NT)
|
||||
/// </summary>
|
||||
NTFS = 11,
|
||||
|
||||
/// <summary>
|
||||
/// QDOS
|
||||
/// </summary>
|
||||
QDOS = 12,
|
||||
|
||||
/// <summary>
|
||||
/// Acorn RISCOS
|
||||
/// </summary>
|
||||
AcornRISCOS = 13,
|
||||
|
||||
/// <summary>
|
||||
/// unknown
|
||||
/// </summary>
|
||||
Unknown = 255,
|
||||
}
|
||||
}
|
||||
26
SabreTools.Models/GZIP/ExtraFieldData.cs
Normal file
26
SabreTools.Models/GZIP/ExtraFieldData.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace SabreTools.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public sealed class ExtraFieldData
|
||||
{
|
||||
/// <summary>
|
||||
/// SI1 and SI2 provide a subfield ID, typically two ASCII letters
|
||||
/// with some mnemonic value.
|
||||
/// </summary>
|
||||
public byte SI1;
|
||||
|
||||
/// <summary>
|
||||
/// SI1 and SI2 provide a subfield ID, typically two ASCII letters
|
||||
/// with some mnemonic value.
|
||||
/// </summary>
|
||||
public byte SI2;
|
||||
|
||||
/// <summary>
|
||||
/// LEN gives the length of the subfield data, excluding the 4
|
||||
/// initial bytes.
|
||||
/// </summary>
|
||||
public ushort LEN;
|
||||
|
||||
public byte[]? Data;
|
||||
}
|
||||
}
|
||||
88
SabreTools.Models/GZIP/Header.cs
Normal file
88
SabreTools.Models/GZIP/Header.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
namespace SabreTools.Models.GZIP
|
||||
{
|
||||
/// <see href="https://www.ietf.org/rfc/rfc1952.txt"/>
|
||||
public sealed class Header
|
||||
{
|
||||
/// <summary>
|
||||
/// IDentification 1 (0x1F)
|
||||
/// </summary>
|
||||
public byte ID1;
|
||||
|
||||
/// <summary>
|
||||
/// IDentification 2 (0x8B)
|
||||
/// </summary>
|
||||
public byte ID2;
|
||||
|
||||
/// <summary>
|
||||
/// Compression Method
|
||||
/// </summary>
|
||||
public CompressionMethod CM;
|
||||
|
||||
/// <summary>
|
||||
/// FLaGs
|
||||
/// </summary>
|
||||
public Flags FLG;
|
||||
|
||||
/// <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
|
||||
/// may cause problems for MS-DOS and other systems that use
|
||||
/// local rather than Universal time.) If the compressed data
|
||||
/// did not come from a file, MTIME is set to the time at which
|
||||
/// compression started. MTIME = 0 means no time stamp is
|
||||
/// available.
|
||||
/// </summary>
|
||||
public uint MTIME;
|
||||
|
||||
/// <summary>
|
||||
/// eXtra FLags
|
||||
/// </summary>
|
||||
public ExtraFlags XFL;
|
||||
|
||||
/// <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.
|
||||
/// </summary>
|
||||
public OperatingSystem OS;
|
||||
|
||||
/// <summary>
|
||||
/// eXtra LENgth
|
||||
///
|
||||
/// If FLG.FEXTRA is set, this gives the length of the optional
|
||||
/// extra field.
|
||||
/// </summary>
|
||||
public ushort XLEN;
|
||||
|
||||
/// <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"/>.
|
||||
/// </summary>
|
||||
public ExtraFieldData[]? ExtraField;
|
||||
|
||||
/// <summary>
|
||||
/// Original filename before compression, zero-terminated
|
||||
/// </summary>
|
||||
public string? OriginalFileName;
|
||||
|
||||
/// <summary>
|
||||
/// File comment, zero terminated
|
||||
/// </summary>
|
||||
public string? FileComment;
|
||||
|
||||
/// <summary>
|
||||
/// The CRC16 consists of the two least significant bytes of the
|
||||
/// CRC32 for all bytes of the gzip header up to and not including
|
||||
/// the CRC16.
|
||||
/// </summary>
|
||||
public ushort? CRC16;
|
||||
}
|
||||
}
|
||||
26
SabreTools.Models/GZIP/Trailer.cs
Normal file
26
SabreTools.Models/GZIP/Trailer.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace SabreTools.Models.GZIP
|
||||
{
|
||||
/// <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
|
||||
/// ITU-T recommendation V.42. (See http://www.iso.ch for
|
||||
/// ordering ISO documents. See gopher://info.itu.ch for an
|
||||
/// online version of ITU-T V.42.)
|
||||
/// </summary>
|
||||
public uint CRC32;
|
||||
|
||||
/// <summary>
|
||||
/// Input SIZE
|
||||
///
|
||||
/// This contains the size of the original (uncompressed) input
|
||||
/// data modulo 2^32.
|
||||
/// </summary>
|
||||
public uint ISIZE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user