1 /******************************************************************************* 2 3 Record definitions for the PKZIP archive file format 4 5 copyright: Copyright (c) 2016 dunnhumby Germany GmbH. All rights reserved 6 7 8 *******************************************************************************/ 9 10 module ocean.util.compress.c.Zip; 11 12 /******************************************************************************* 13 14 Signatures of the records in a Zip archive. Each record is preceded by the 15 corresponding signature, except for ZipLocalFileSizeSignature, which is 16 permitted to be missing. 17 18 All signatures begin with "PK", the initials of Phil Katz, who created the 19 format. 20 21 *******************************************************************************/ 22 23 static string ZipCentralDirectoryFileHeaderSignature = "PK\x01\x02"; 24 25 /** ditto **/ 26 27 static string ZipLocalFileHeaderSignature = "PK\x03\x04"; 28 29 /** ditto **/ 30 31 static string ZipEndOfCentralDirectorySignature = "PK\x05\x06"; 32 33 /** ditto **/ 34 35 static string ZipLocalFileSizeSignature = "PK\x07\x08"; 36 37 38 39 /******************************************************************************* 40 41 Struct which is stored at the start of each file in the archive 42 43 This record will always be preceded by a ZipLocalFileHeaderSignature. 44 This is an incomplete, redundant copy of the struct in the central 45 directory. 46 47 *******************************************************************************/ 48 49 public align(1) struct ZipLocalFileHeaderRecord 50 { 51 align(1): 52 ushort extract_version; 53 ushort general_flags; 54 ushort compression_method; 55 ushort modification_file_time; 56 ushort modification_file_date; 57 uint crc_32; 58 uint compressed_size; 59 uint uncompressed_size; 60 ushort file_name_length; 61 ushort extra_field_length; 62 63 /*********************************************************************** 64 65 Returns: 66 true if the CRC and file sizes were not known when the object 67 was written. In this case, the values are stored in a 68 ZipLocalFileSizeRecord after the compressed data. There may or 69 may not be a ZipLocalFileSizeSignature before the record. 70 71 ***********************************************************************/ 72 73 public final bool isCrcMissing ( ) 74 { 75 return (this.general_flags & 0x08 ) == 0x08; 76 } 77 78 79 /*************************************************************************** 80 81 Returns: 82 true if and only if the file is compressed using the DEFLATE method 83 84 ***************************************************************************/ 85 86 public final bool isDeflateCompressed () 87 { 88 return this.compression_method == 8; 89 } 90 } 91 92 93 /******************************************************************************* 94 95 Struct which is stored at the end of a file if the CRC and length were not 96 known when the file compression began. 97 98 This struct may optionally be preceded by a ZipLocalFileSizeSignature. 99 100 *******************************************************************************/ 101 102 public align(1) struct ZipLocalFileSizeRecord 103 { 104 align(1): 105 uint crc_32; 106 uint compressed_size; 107 uint uncompressed_size; 108 } 109 110 111 /******************************************************************************* 112 113 Struct which is stored at the end of the archive. It is followed by a 114 comment of length up to 65535 bytes. 115 116 This record will always be preceded by a 117 ZipCentralDirectoryFileHeaderSignature. 118 119 *******************************************************************************/ 120 121 public align(1) struct ZipCentralDirectoryFileHeaderRecord 122 { 123 align(1): 124 ubyte zip_version; 125 ubyte file_attribute_type; 126 ushort extract_version; 127 ushort general_flags; 128 ushort compression_method; 129 ushort modification_file_time; 130 ushort modification_file_date; 131 uint crc_32; 132 uint compressed_size; 133 uint uncompressed_size; 134 ushort file_name_length; 135 ushort extra_field_length; 136 ushort file_comment_length; 137 ushort disk_number_start; 138 ushort internal_file_attributes; 139 uint external_file_attributes; 140 int relative_offset_of_local_header; 141 } 142 143 144 /******************************************************************************* 145 146 Struct which is stored at the end of the archive. It is followed by a 147 comment of length up to 65535 bytes. 148 149 This record will always be preceded by a 150 ZipEndOfCentralDirectorySignature 151 152 *******************************************************************************/ 153 154 public align(1) struct EndOfCentralDirectoryRecord 155 { 156 align(1): 157 ushort disk_number; 158 ushort disk_with_start_of_central_directory; 159 ushort central_directory_entries_on_this_disk; 160 ushort central_directory_entries_total; 161 uint size_of_central_directory; 162 uint offset_of_start_of_cd_from_starting_disk; 163 ushort file_comment_length; 164 }