beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / zzip / format.h
blob0881479c16722179075e78731778fc77e1d832a6
1 /*
2 * Author:
3 * Guido Draheim <guidod@gmx.de>
5 * Copyright (c) 2000,2001,2002,2003 Guido Draheim
6 * All rights reserved
7 * use under the restrictions of the
8 * Lesser GNU General Public License
9 * or alternatively the restrictions
10 * of the Mozilla Public License 1.1
12 * The information was taken from appnote-981119-iz.zip
13 * at http://www.freesoftware.com/pub/infozip/doc/
14 * which in turn is based on PKWARE's appnote.txt
15 * (newer link: ftp://ftp.info-zip.org/pub/infozip/doc/)
17 #ifndef _ZZIP_FORMAT_H /* zzipformat.h */
18 #define _ZZIP_FORMAT_H
20 #include <zzip/types.h>
21 #include <zzip/__hints.h>
22 /* we have ICO C 9X types defined */
25 * Overall zipfile format
26 * [local file header + file data stream + checksum descriptor] ...
27 * ... [disk central directory] [disk trailer record]
30 # ifdef _MSC_VER
31 # pragma pack(push, 1)
32 # endif
34 struct zzip_version
36 zzip_byte_t version[1];
37 zzip_byte_t ostype[1];
38 } ZZIP_GNUC_PACKED;
40 struct zzip_dostime
42 zzip_byte_t time[2];
43 zzip_byte_t date[2];
44 } ZZIP_GNUC_PACKED;
46 #ifdef ZZIP_NEED_PACKED
47 /* if your compiler does interesting things about struct packing... */
48 typedef zzip_byte_t zzip_version_t[2];
49 typedef zzip_byte_t zzip_dostime_t[4];
50 #else
51 typedef struct zzip_version zzip_version_t;
52 typedef struct zzip_dostime zzip_dostime_t;
53 #endif
55 #define ZZIP_CHECKMAGIC(__p,__A,__B,__C,__D) \
56 ( (((zzip_byte_t*)(__p))[0]==(__A)) && \
57 (((zzip_byte_t*)(__p))[1]==(__B)) && \
58 (((zzip_byte_t*)(__p))[2]==(__C)) && \
59 (((zzip_byte_t*)(__p))[3]==(__D)) )
61 /* A. Local file header */
62 struct zzip_file_header
64 # define ZZIP_FILE_HEADER_MAGIC 0x04034b50
65 # define ZZIP_FILE_HEADER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\3','\4')
66 zzip_byte_t z_magic[4]; /* local file header signature (0x04034b50) */
67 zzip_version_t z_extract; /* version needed to extract */
68 zzip_byte_t z_flags[2]; /* general purpose bit flag */
69 zzip_byte_t z_compr[2]; /* compression method */
70 zzip_dostime_t z_dostime; /* last mod file time (dos format) */
71 zzip_byte_t z_crc32[4]; /* crc-32 */
72 zzip_byte_t z_csize[4]; /* compressed size */
73 zzip_byte_t z_usize[4]; /* uncompressed size */
74 zzip_byte_t z_namlen[2]; /* filename length (null if stdin) */
75 zzip_byte_t z_extras[2]; /* extra field length */
76 /* followed by filename (of variable size) */
77 /* followed by extra field (of variable size) */
78 } ZZIP_GNUC_PACKED;
79 #define zzip_file_header_headerlength (4+2+2+2+4+4+4+4+2+2)
81 /* B. data descriptor
82 * the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned
83 * and immediately follows the last byte of compressed data. It is only used if
84 * the output media of the compressor was not seekable, eg. standard output.
86 struct zzip_file_trailer
88 # define ZZIP_FILE_TRAILER_MAGIC 0x08074B50
89 # define ZZIP_FILE_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\7','\8')
90 zzip_byte_t z_magic[4]; /* data descriptor signature (0x08074b50) */
91 zzip_byte_t z_crc32[4]; /* crc-32 */
92 zzip_byte_t z_csize[4]; /* compressed size */
93 zzip_byte_t z_usize[4]; /* uncompressed size */
94 } ZZIP_GNUC_PACKED;
95 #define zzip_file_trailer_headerlength (4+4+4+4)
97 /* C. central directory structure:
98 [file header] . . . end of central dir record
101 /* directory file header
102 * - a single entry including filename, extras and comment may not exceed 64k.
105 struct zzip_disk_entry
107 # define ZZIP_DISK_ENTRY_MAGIC 0x02014b50
108 # define ZZIP_DISK_ENTRY_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\1','\2')
109 zzip_byte_t z_magic[4]; /* central file header signature (0x02014b50) */
110 zzip_version_t z_encoder; /* version made by */
111 zzip_version_t z_extract; /* version need to extract */
112 zzip_byte_t z_flags[2]; /* general purpose bit flag */
113 zzip_byte_t z_compr[2]; /* compression method */
114 zzip_dostime_t z_dostime; /* last mod file time&date (dos format) */
115 zzip_byte_t z_crc32[4]; /* crc-32 */
116 zzip_byte_t z_csize[4]; /* compressed size */
117 zzip_byte_t z_usize[4]; /* uncompressed size */
118 zzip_byte_t z_namlen[2]; /* filename length (null if stdin) */
119 zzip_byte_t z_extras[2]; /* extra field length */
120 zzip_byte_t z_comment[2]; /* file comment length */
121 zzip_byte_t z_diskstart[2]; /* disk number of start (if spanning zip over multiple disks) */
122 zzip_byte_t z_filetype[2]; /* internal file attributes, bit0 = ascii */
123 zzip_byte_t z_filemode[4]; /* extrnal file attributes, eg. msdos attrib byte */
124 zzip_byte_t z_offset[4]; /* relative offset of local file header, seekval if singledisk */
125 /* followed by filename (of variable size) */
126 /* followed by extra field (of variable size) */
127 /* followed by file comment (of variable size) */
128 } ZZIP_GNUC_PACKED;
129 #define zzip_disk_entry_headerlength (4+2+2+2+2+4+4+4+4+2+2+2+2+2+4+4)
132 struct zzip_root_dirent
133 { /* the old name of the structure above */
134 # define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50
135 # define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_DISK_ENTRY_CHECKMAGIC(__p)
136 zzip_byte_t z_magic[4];
137 zzip_version_t z_encoder;
138 zzip_version_t z_extract;
139 zzip_byte_t z_flags[2];
140 zzip_byte_t z_compr[2];
141 zzip_dostime_t z_dostime;
142 zzip_byte_t z_crc32[4];
143 zzip_byte_t z_csize[4];
144 zzip_byte_t z_usize[4];
145 zzip_byte_t z_namlen[2];
146 zzip_byte_t z_extras[2];
147 zzip_byte_t z_comment[2];
148 zzip_byte_t z_diskstart[2];
149 zzip_byte_t z_filetype[2];
150 zzip_byte_t z_filemode[4];
151 zzip_byte_t z_off[4];
152 } ZZIP_GNUC_PACKED;
155 /* end of central dir record */
156 struct zzip_disk_trailer
158 # define ZZIP_DISK_TRAILER_MAGIC 0x06054b50
159 # define ZZIP_DISK_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\5','\6')
160 zzip_byte_t z_magic[4]; /* end of central dir signature (0x06054b50) */
161 zzip_byte_t z_disk[2]; /* number of this disk */
162 zzip_byte_t z_finaldisk[2]; /* number of the disk with the start of the central dir */
163 zzip_byte_t z_entries[2]; /* total number of entries in the central dir on this disk */
164 zzip_byte_t z_finalentries[2]; /* total number of entries in the central dir */
165 zzip_byte_t z_rootsize[4]; /* size of the central directory */
166 zzip_byte_t z_rootseek[4]; /* offset of start of central directory with respect to *
167 * the starting disk number */
168 zzip_byte_t z_comment[2]; /* zipfile comment length */
169 /* followed by zipfile comment (of variable size) */
170 } ZZIP_GNUC_PACKED;
171 #define zzip_disk_trailer_headerlength (4+2+2+2+2+4+4+2)
173 /* extra field should be type + size + data + type + size + data ... */
174 struct zzip_extra_block
175 { /* fetch.h macros do not need this struct */
176 zzip_byte_t z_datatype[2]; /* as input type - a mere <char*> is okay */
177 zzip_byte_t z_datasize[2]; /* being returned by xx_to_extras usually */
178 } ZZIP_GNUC_PACKED;
179 #define zzip_extra_block_headerlength (2+2)
181 /* Zip64 end of central dir record */
182 struct zzip_disk64_trailer
184 # define ZZIP_DISK64_TRAILER_MAGIC 0x06064b50
185 # define ZZIP_DISK64_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\6','\6')
186 zzip_byte_t z_magic[4]; /* end of central dir signature (0x06054b50) */
187 zzip_byte_t z_size[8]; /* size of this central directory record */
188 zzip_version_t z_encoder; /* version made by */
189 zzip_version_t z_extract; /* version need to extract */
190 zzip_byte_t z_disk[4]; /* number of this disk */
191 zzip_byte_t z_finaldisk[4]; /* number of the disk with the start of the central dir */
192 zzip_byte_t z_entries[8]; /* total number of entries in the central dir on this disk */
193 zzip_byte_t z_finalentries[8]; /* total number of entries in the central dir */
194 zzip_byte_t z_rootsize[8]; /* size of the central directory */
195 zzip_byte_t z_rootseek[8]; /* offset of start of central directory with respect to *
196 * the starting disk number */
197 /* followed by zip64 extensible data sector (of variable size) */
198 } ZZIP_GNUC_PACKED;
199 #define zzip_disk64_trailer_headerlength (4+8+2+2+4+4+8+8+8+8)
201 /* z_flags */
202 #define ZZIP_IS_ENCRYPTED(p) ((*(zzip_byte_t*)p)&1)
203 #define ZZIP_IS_COMPRLEVEL(p) (((*(zzip_byte_t*)p)>>1)&3)
204 #define ZZIP_IS_STREAMED(p) (((*(zzip_byte_t*)p)>>3)&1)
205 #define ZZIP_IS_PATCHED(p) (((*(zzip_byte_t*)p)>>5)&1)
207 /* z_compr */
208 #define ZZIP_IS_STORED 0
209 #define ZZIP_IS_SHRUNK 1
210 #define ZZIP_IS_REDUCEDx1 2
211 #define ZZIP_IS_REDUCEDx2 3
212 #define ZZIP_IS_REDUCEDx3 4
213 #define ZZIP_IS_REDUCEDx4 5
214 #define ZZIP_IS_IMPLODED 6
215 #define ZZIP_IS_TOKENIZED 7
216 #define ZZIP_IS_DEFLATED 8
217 #define ZZIP_IS_DEFLATED_BETTER 9
218 #define ZZIP_IS_IMPLODED_BETTER 10
220 /* deflated comprlevel */
221 #define ZZIP_DEFLATED_STD_COMPR 0
222 #define ZZIP_DEFLATED_MAX_COMPR 1
223 #define ZZIP_DEFLATED_LOW_COMPR 2
224 #define ZZIP_DEFLATED_MIN_COMPR 3
226 # ifdef _MSC_VER
227 # pragma pack(pop)
228 # endif
230 #endif /* _ZZIPFORMAT_H */