1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unzip.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 *************************************************************************/
31 /* unzip.h -- IO for uncompress .zip files using zlib
32 Version 1.01e, February 12th, 2005
34 Copyright (C) 1998-2005 Gilles Vollant
36 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
37 WinZip, InfoZip tools and compatible.
39 Multi volume ZipFile (span) are not supported.
40 Encryption compatible with pkzip 2.04g only supported
41 Old compressions used by old PKZip 1.x are not supported
44 I WAIT FEEDBACK at mail info@winimage.com
45 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
47 Condition of use and distribution are the same than zlib :
49 This software is provided 'as-is', without any express or implied
50 warranty. In no event will the authors be held liable for any damages
51 arising from the use of this software.
53 Permission is granted to anyone to use this software for any purpose,
54 including commercial applications, and to alter it and redistribute it
55 freely, subject to the following restrictions:
57 1. The origin of this software must not be misrepresented; you must not
58 claim that you wrote the original software. If you use this software
59 in a product, an acknowledgment in the product documentation would be
60 appreciated but is not required.
61 2. Altered source versions must be plainly marked as such, and must not be
62 misrepresented as being the original software.
63 3. This notice may not be removed or altered from any source distribution.
68 /* for more info about .ZIP format, see
69 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
70 http://www.info-zip.org/pub/infozip/doc/
71 PkWare has also a specification at :
72 ftp://ftp.pkware.com/probdesc.zip
86 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
87 /* like the STRICT of WIN32, we define a pointer that cannot be converted
88 from (void*) without cast */
89 typedef struct TagunzFile__
{ int unused
; } unzFile__
;
90 typedef unzFile__
*unzFile
;
92 typedef voidp unzFile
;
97 #define UNZ_END_OF_LIST_OF_FILE (-100)
98 #define UNZ_ERRNO (Z_ERRNO)
100 #define UNZ_PARAMERROR (-102)
101 #define UNZ_BADZIPFILE (-103)
102 #define UNZ_INTERNALERROR (-104)
103 #define UNZ_CRCERROR (-105)
105 /* tm_unz contain date/time info */
106 typedef struct tm_unz_s
108 uInt tm_sec
; /* seconds after the minute - [0,59] */
109 uInt tm_min
; /* minutes after the hour - [0,59] */
110 uInt tm_hour
; /* hours since midnight - [0,23] */
111 uInt tm_mday
; /* day of the month - [1,31] */
112 uInt tm_mon
; /* months since January - [0,11] */
113 uInt tm_year
; /* years - [1980..2044] */
116 /* unz_global_info structure contain global data about the ZIPfile
117 These data comes from the end of central dir */
118 typedef struct unz_global_info_s
120 uLong number_entry
; /* total number of entries in
121 the central dir on this disk */
122 uLong size_comment
; /* size of the global comment of the zipfile */
126 /* unz_file_info contain information about a file in the zipfile */
127 typedef struct unz_file_info_s
129 uLong version
; /* version made by 2 bytes */
130 uLong version_needed
; /* version needed to extract 2 bytes */
131 uLong flag
; /* general purpose bit flag 2 bytes */
132 uLong compression_method
; /* compression method 2 bytes */
133 uLong dosDate
; /* last mod file date in Dos fmt 4 bytes */
134 uLong crc
; /* crc-32 4 bytes */
135 uLong compressed_size
; /* compressed size 4 bytes */
136 uLong uncompressed_size
; /* uncompressed size 4 bytes */
137 uLong size_filename
; /* filename length 2 bytes */
138 uLong size_file_extra
; /* extra field length 2 bytes */
139 uLong size_file_comment
; /* file comment length 2 bytes */
141 uLong disk_num_start
; /* disk number start 2 bytes */
142 uLong internal_fa
; /* internal file attributes 2 bytes */
143 uLong external_fa
; /* external file attributes 4 bytes */
148 extern int ZEXPORT unzStringFileNameCompare
OF ((const char* fileName1
,
149 const char* fileName2
,
150 int iCaseSensitivity
));
152 Compare two filename (fileName1,fileName2).
153 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
154 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
156 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
157 (like 1 on Unix, 2 on Windows)
161 extern unzFile ZEXPORT unzOpen
OF((const char *path
));
163 Open a Zip file. path contain the full pathname (by example,
164 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
166 If the zipfile cannot be opened (file don't exist or in not valid), the
167 return value is NULL.
168 Else, the return value is a unzFile Handle, usable with other function
169 of this unzip package.
172 extern unzFile ZEXPORT unzOpen2
OF((const char *path
,
173 zlib_filefunc_def
* pzlib_filefunc_def
));
175 Open a Zip file, like unzOpen, but provide a set of file low level API
176 for read/write the zip file (see ioapi.h)
179 extern int ZEXPORT unzClose
OF((unzFile file
));
181 Close a ZipFile opened with unzipOpen.
182 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
183 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
184 return UNZ_OK if there is no problem. */
186 extern int ZEXPORT unzGetGlobalInfo
OF((unzFile file
,
187 unz_global_info
*pglobal_info
));
189 Write info about the ZipFile in the *pglobal_info structure.
190 No preparation of the structure is needed
191 return UNZ_OK if there is no problem. */
194 extern int ZEXPORT unzGetGlobalComment
OF((unzFile file
,
198 Get the global comment string of the ZipFile, in the szComment buffer.
199 uSizeBuf is the size of the szComment buffer.
200 return the number of byte copied or an error code <0
204 /***************************************************************************/
205 /* Unzip package allow you browse the directory of the zipfile */
207 extern int ZEXPORT unzGoToFirstFile
OF((unzFile file
));
209 Set the current file of the zipfile to the first file.
210 return UNZ_OK if there is no problem
213 extern int ZEXPORT unzGoToNextFile
OF((unzFile file
));
215 Set the current file of the zipfile to the next file.
216 return UNZ_OK if there is no problem
217 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
220 extern int ZEXPORT unzLocateFile
OF((unzFile file
,
221 const char *szFileName
,
222 int iCaseSensitivity
));
224 Try locate the file szFileName in the zipfile.
225 For the iCaseSensitivity signification, see unzStringFileNameCompare
228 UNZ_OK if the file is found. It becomes the current file.
229 UNZ_END_OF_LIST_OF_FILE if the file is not found
233 /* ****************************************** */
234 /* Ryan supplied functions */
235 /* unz_file_info contain information about a file in the zipfile */
236 typedef struct unz_file_pos_s
238 uLong pos_in_zip_directory
; /* offset in zip file directory */
239 uLong num_of_file
; /* # of file */
242 extern int ZEXPORT
unzGetFilePos(
244 unz_file_pos
* file_pos
);
246 extern int ZEXPORT
unzGoToFilePos(
248 unz_file_pos
* file_pos
);
250 /* ****************************************** */
252 extern int ZEXPORT unzGetCurrentFileInfo
OF((unzFile file
,
253 unz_file_info
*pfile_info
,
255 uLong fileNameBufferSize
,
257 uLong extraFieldBufferSize
,
259 uLong commentBufferSize
));
261 Get Info about the current file
262 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
264 if szFileName!=NULL, the filemane string will be copied in szFileName
265 (fileNameBufferSize is the size of the buffer)
266 if extraField!=NULL, the extra field information will be copied in extraField
267 (extraFieldBufferSize is the size of the buffer).
268 This is the Central-header version of the extra field
269 if szComment!=NULL, the comment string of the file will be copied in szComment
270 (commentBufferSize is the size of the buffer)
273 /***************************************************************************/
274 /* for reading the content of the current zipfile, you can open it, read data
275 from it, and close it (you can close it before reading all the file)
278 extern int ZEXPORT unzOpenCurrentFile
OF((unzFile file
));
280 Open for reading data the current file in the zipfile.
281 If there is no error, the return value is UNZ_OK.
284 extern int ZEXPORT unzOpenCurrentFilePassword
OF((unzFile file
,
285 const char* password
));
287 Open for reading data the current file in the zipfile.
288 password is a crypting password
289 If there is no error, the return value is UNZ_OK.
292 extern int ZEXPORT unzOpenCurrentFile2
OF((unzFile file
,
297 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
299 *method will receive method of compression, *level will receive level of
301 note : you can set level parameter as NULL (if you did not want known level,
302 but you CANNOT set method parameter as NULL
305 extern int ZEXPORT unzOpenCurrentFile3
OF((unzFile file
,
309 const char* password
));
311 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
313 *method will receive method of compression, *level will receive level of
315 note : you can set level parameter as NULL (if you did not want known level,
316 but you CANNOT set method parameter as NULL
320 extern int ZEXPORT unzCloseCurrentFile
OF((unzFile file
));
322 Close the file in zip opened with unzOpenCurrentFile
323 Return UNZ_CRCERROR if all the file was read but the CRC is not good
326 extern int ZEXPORT unzReadCurrentFile
OF((unzFile file
,
330 Read bytes from the current file (opened by unzOpenCurrentFile)
331 buf contain buffer where data must be copied
334 return the number of byte copied if somes bytes are copied
335 return 0 if the end of file was reached
336 return <0 with error code if there is an error
337 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
340 extern z_off_t ZEXPORT unztell
OF((unzFile file
));
342 Give the current position in uncompressed data
345 extern int ZEXPORT unzeof
OF((unzFile file
));
347 return 1 if the end of file was reached, 0 elsewhere
350 extern int ZEXPORT unzGetLocalExtrafield
OF((unzFile file
,
354 Read extra field from the current file (opened by unzOpenCurrentFile)
355 This is the local-header version of the extra field (sometimes, there is
356 more info in the local-header version than in the central-header)
358 if buf==NULL, it return the size of the local extra field
360 if buf!=NULL, len is the size of the buffer, the extra header is copied in
362 the return value is the number of bytes copied in buf, or (if <0)
366 /***************************************************************************/
368 /* Get the current file offset */
369 extern uLong ZEXPORT
unzGetOffset (unzFile file
);
371 /* Set the current file offset */
372 extern int ZEXPORT
unzSetOffset (unzFile file
, uLong pos
);