/Utilities/Compression/ZipConstants.cs
C# | 326 lines | 77 code | 57 blank | 192 comment | 0 complexity | cc39a95072dcbfec90cde7a2ec0c18e3 MD5 | raw file
Possible License(s): Apache-2.0
- // Based on Mike Krueger's SharpZipLib, Copyright (C) 2001 (GNU license).
- // Authors of the original java version: Jochen Hoenicke, John Leuner
- // See http://www.ISeeSharpCode.com for more information.
-
- using System.Text;
-
- namespace Delta.Utilities.Compression
- {
- /// <summary>
- /// This class contains constants used for Zip format files
- /// </summary>
- public sealed class ZipConstants
- {
- #region Constants
- /// <summary>
- /// The version made by field for entries in the central header when
- /// created by this library
- /// </summary>
- /// <remarks>
- /// This is also the Zip version for the library when comparing against
- /// the version required to extract for an entry. See
- /// <see cref="Streams.ZipInputStream.CanDecompressEntry">
- /// ZipInputStream.CanDecompressEntry</see>.
- /// </remarks>
- public const int VersionMadeBy = 20;
-
- /// <summary>
- /// The minimum version required to support strong encryption
- /// </summary>
- public const int VersionStrongEncryption = 50;
-
- // The local entry header
-
- /// <summary>
- /// Size of local entry header (excluding variable length fields at end)
- /// </summary>
- public const int LocalHeader = 30;
-
- /// <summary>
- /// Signature for local entry header
- /// </summary>
- public const int LocalSignature = 'P' | ('K' << 8) | (3 << 16) | (4 << 24);
-
- /// <summary>
- /// Offset of version to extract in local entry header
- /// </summary>
- public const int LocalVersion = 4;
-
- /// <summary>
- /// Offset of general purpose flags in local entry header
- /// </summary>
- public const int LocalFlag = 6;
-
- /// <summary>
- /// Offset of compression method in local entry header
- /// </summary>
- public const int LocalHow = 8;
-
- /// <summary>
- /// Offset of last mod file time + date in local entry header
- /// </summary>
- public const int LocalTime = 10;
-
- /// <summary>
- /// Offset of crc-32 in local entry header
- /// </summary>
- public const int LocalCrc = 14;
-
- /// <summary>
- /// Offset of compressed size in local entry header
- /// </summary>
- public const int LocalSize = 18;
-
- /// <summary>
- /// Offset of uncompressed size in local entry header
- /// </summary>
- public const int LocalLength = 22;
-
- /// <summary>
- /// Offset of file name length in local entry header
- /// </summary>
- public const int LocalName = 26;
-
- /// <summary>
- /// Offset of extra field length in local entry header
- /// </summary>
- public const int LocalExtension = 28;
-
- /// <summary>
- /// Signature for spanning entry
- /// </summary>
- public const int SpanningSig =
- 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
-
- /// <summary>
- /// Signature for temporary spanning entry
- /// </summary>
- public const int SpanningTempSig =
- 'P' | ('K' << 8) | ('0' << 16) | ('0' << 24);
-
- /// <summary>
- /// Signature for data descriptor
- /// </summary>
- /// <remarks>
- /// This is only used where the length, Crc, or compressed size isn't
- /// known when the entry is created and the output stream doesnt support
- /// seeking. The local entry cannot be 'patched' with the correct values
- /// in this case so the values are recorded after the data prefixed by
- /// this header, as well as in the central directory.
- /// </remarks>
- public const int ExternSig =
- 'P' | ('K' << 8) | (7 << 16) | (8 << 24);
-
- /// <summary>
- /// Size of data descriptor
- /// </summary>
- public const int ExternHeader = 16;
-
- /// <summary>
- /// Offset of crc-32 in data descriptor
- /// </summary>
- public const int ExternCrc = 4;
-
- /// <summary>
- /// Offset of compressed size in data descriptor
- /// </summary>
- public const int ExternSize = 8;
-
- /// <summary>
- /// Offset of uncompressed length in data descriptor
- /// </summary>
- public const int ExternLength = 12;
-
- /// <summary>
- /// Signature for central header
- /// </summary>
- public const int CentralDirectorySig =
- 'P' | ('K' << 8) | (1 << 16) | (2 << 24);
-
- /// <summary>
- /// Signature for Zip64 central file header
- /// </summary>
- public const int CentralDirectorySig64 =
- 'P' | ('K' << 8) | (6 << 16) | (6 << 24);
-
- /// <summary>
- /// Central header digitial signature
- /// </summary>
- public const int CentralDigitalSig =
- 'P' | ('K' << 8) | (5 << 16) | (5 << 24);
-
- /// <summary>
- /// Size of central header entry
- /// </summary>
- public const int CentralHeader = 46;
-
- /// <summary>
- /// Offset of version made by in central file header
- /// </summary>
- public const int CentralVem = 4;
-
- /// <summary>
- /// Offset of version needed to extract in central file header
- /// </summary>
- public const int CentralVersion = 6;
-
- /// <summary>
- /// Offset of general purpose bit flag in central file header
- /// </summary>
- public const int CentralFlag = 8;
-
- /// <summary>
- /// Offset of compression method in central file header
- /// </summary>
- public const int CentralHow = 10;
-
- /// <summary>
- /// Offset of time/date in central file header
- /// </summary>
- public const int CentralTime = 12;
-
- /// <summary>
- /// Offset of crc-32 in central file header
- /// </summary>
- public const int CentralCrc = 16;
-
- /// <summary>
- /// Offset of compressed size in central file header
- /// </summary>
- public const int CentralSize = 20;
-
- /// <summary>
- /// Offset of uncompressed size in central file header
- /// </summary>
- public const int CentralLength = 24;
-
- /// <summary>
- /// Offset of file name length in central file header
- /// </summary>
- public const int CentralName = 28;
-
- /// <summary>
- /// Offset of extra field length in central file header
- /// </summary>
- public const int CentralExtension = 30;
-
- /// <summary>
- /// Offset of file comment length in central file header
- /// </summary>
- public const int CentralComment = 32;
-
- /// <summary>
- /// Offset of disk start number in central file header
- /// </summary>
- public const int CentralDiskStartNumber = 34;
-
- /// <summary>
- /// Offset of internal file attributes in central file header
- /// </summary>
- public const int CentralAttributes = 36;
-
- /// <summary>
- /// Offset of external file attributes in central file header
- /// </summary>
- public const int CentralExternalAttributes = 38;
-
- /// <summary>
- /// Offset of relative offset of local header in central file header
- /// </summary>
- public const int CentralOffset = 42;
-
- // The entries at the end of central directory
-
- /// <summary>
- /// End of central directory record signature
- /// </summary>
- public const int EndSig =
- 'P' | ('K' << 8) | (5 << 16) | (6 << 24);
-
- /// <summary>
- /// Size of end of central record (excluding variable fields)
- /// </summary>
- public const int EndHeader = 22;
-
- // The following two fields are missing in SUN JDK
-
- /// <summary>
- /// Offset of number of this disk
- /// </summary>
- public const int EndNumberOfDisk = 4;
-
- /// <summary>
- /// Offset of number of disk with start of central directory
- /// </summary>
- public const int EndNumberOfDiskCentralDirectory = 6;
-
- /// <summary>
- /// Offset of number of entries in the central directory of this disk
- /// </summary>
- public const int EndEntriesInCentralDirectory = 8;
-
- /// <summary>
- /// Offset of total number of entries in the central directory
- /// </summary>
- public const int EndTotalNumberOfEntriesInCentralDirectory = 10;
-
- /// <summary>
- /// Offset of size of central directory
- /// </summary>
- public const int EndSizeOfCentralDirectory = 12;
-
- /// <summary>
- /// Offset of offset of start of central directory with respect to
- /// starting disk number
- /// </summary>
- public const int EndOffset = 16;
-
- /// <summary>
- /// Offset of ZIP file comment length
- /// </summary>
- public const int EndComment = 20;
-
- /// <summary>
- /// Size of cryptographic header stored before entry data
- /// </summary>
- public const int CryptoHeaderSize = 12;
- #endregion
-
- #region Public
- #endregion
-
- #region Convert methods
- /// <summary>
- /// Convert a portion of a byte array to a string.
- /// </summary>
- /// <param name="data">
- /// Data to convert to string
- /// </param>
- /// <param name="length">
- /// Number of bytes to convert starting from index 0
- /// </param>
- /// <returns>
- /// data[0]..data[length - 1] converted to a string
- /// </returns>
- public static string ConvertToString(byte[] data, int length)
- {
- return Encoding.ASCII.GetString(data, 0, length);
- }
-
- /// <summary>
- /// Convert byte array to string
- /// </summary>
- /// <param name="data">
- /// Byte array to convert
- /// </param>
- /// <returns>
- /// <paramref name="data">data</paramref>converted to a string
- /// </returns>
- public static string ConvertToString(byte[] data)
- {
- return ConvertToString(data, data.Length);
- }
- #endregion
- }
- }
-