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 moduleocean.util.compress.c.Zip;
11 12 13 importocean.meta.types.Qualifiers : istring;
14 15 16 /*******************************************************************************
17 18 Signatures of the records in a Zip archive. Each record is preceded by the
19 corresponding signature, except for ZipLocalFileSizeSignature, which is
20 permitted to be missing.
21 22 All signatures begin with "PK", the initials of Phil Katz, who created the
23 format.
24 25 *******************************************************************************/26 27 staticistringZipCentralDirectoryFileHeaderSignature = "PK\x01\x02";
28 29 /** ditto **/30 31 staticistringZipLocalFileHeaderSignature = "PK\x03\x04";
32 33 /** ditto **/34 35 staticistringZipEndOfCentralDirectorySignature = "PK\x05\x06";
36 37 /** ditto **/38 39 staticistringZipLocalFileSizeSignature = "PK\x07\x08";
40 41 42 43 /*******************************************************************************
44 45 Struct which is stored at the start of each file in the archive
46 47 This record will always be preceded by a ZipLocalFileHeaderSignature.
48 This is an incomplete, redundant copy of the struct in the central
49 directory.
50 51 *******************************************************************************/52 53 publicalign(1) structZipLocalFileHeaderRecord54 {
55 align(1):
56 ushortextract_version;
57 ushortgeneral_flags;
58 ushortcompression_method;
59 ushortmodification_file_time;
60 ushortmodification_file_date;
61 uintcrc_32;
62 uintcompressed_size;
63 uintuncompressed_size;
64 ushortfile_name_length;
65 ushortextra_field_length;
66 67 /***********************************************************************
68 69 Returns:
70 true if the CRC and file sizes were not known when the object
71 was written. In this case, the values are stored in a
72 ZipLocalFileSizeRecord after the compressed data. There may or
73 may not be a ZipLocalFileSizeSignature before the record.
74 75 ***********************************************************************/76 77 publicfinalboolisCrcMissing ( )
78 {
79 return (this.general_flags & 0x08 ) == 0x08;
80 }
81 82 83 /***************************************************************************
84 85 Returns:
86 true if and only if the file is compressed using the DEFLATE method
87 88 ***************************************************************************/89 90 publicfinalboolisDeflateCompressed ()
91 {
92 returnthis.compression_method == 8;
93 }
94 }
95 96 97 /*******************************************************************************
98 99 Struct which is stored at the end of a file if the CRC and length were not
100 known when the file compression began.
101 102 This struct may optionally be preceded by a ZipLocalFileSizeSignature.
103 104 *******************************************************************************/105 106 publicalign(1) structZipLocalFileSizeRecord107 {
108 align(1):
109 uintcrc_32;
110 uintcompressed_size;
111 uintuncompressed_size;
112 }
113 114 115 /*******************************************************************************
116 117 Struct which is stored at the end of the archive. It is followed by a
118 comment of length up to 65535 bytes.
119 120 This record will always be preceded by a
121 ZipCentralDirectoryFileHeaderSignature.
122 123 *******************************************************************************/124 125 publicalign(1) structZipCentralDirectoryFileHeaderRecord126 {
127 align(1):
128 ubytezip_version;
129 ubytefile_attribute_type;
130 ushortextract_version;
131 ushortgeneral_flags;
132 ushortcompression_method;
133 ushortmodification_file_time;
134 ushortmodification_file_date;
135 uintcrc_32;
136 uintcompressed_size;
137 uintuncompressed_size;
138 ushortfile_name_length;
139 ushortextra_field_length;
140 ushortfile_comment_length;
141 ushortdisk_number_start;
142 ushortinternal_file_attributes;
143 uintexternal_file_attributes;
144 intrelative_offset_of_local_header;
145 }
146 147 148 /*******************************************************************************
149 150 Struct which is stored at the end of the archive. It is followed by a
151 comment of length up to 65535 bytes.
152 153 This record will always be preceded by a
154 ZipEndOfCentralDirectorySignature
155 156 *******************************************************************************/157 158 publicalign(1) structEndOfCentralDirectoryRecord159 {
160 align(1):
161 ushortdisk_number;
162 ushortdisk_with_start_of_central_directory;
163 ushortcentral_directory_entries_on_this_disk;
164 ushortcentral_directory_entries_total;
165 uintsize_of_central_directory;
166 uintoffset_of_start_of_cd_from_starting_disk;
167 ushortfile_comment_length;
168 }