1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
24 * Daniel Veditz <dveditz@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
43 * This module implements a simple archive extractor for the PKZIP format.
45 * All functions return a status/error code, and have an opaque hZip argument
46 * that represents an open archive.
48 * Currently only compression mode 8 (or none) is supported.
54 #define ZIP_ERR_GENERAL -1
55 #define ZIP_ERR_MEMORY -2
56 #define ZIP_ERR_DISK -3
57 #define ZIP_ERR_CORRUPT -4
58 #define ZIP_ERR_PARAM -5
59 #define ZIP_ERR_FNF -6
60 #define ZIP_ERR_UNSUPPORTED -7
61 #define ZIP_ERR_SMALLBUF -8
65 /* Open and close the archive
67 * If successful OpenArchive returns a handle in the hZip parameter
68 * that must be passed to all subsequent operations on the archive
70 PR_EXTERN(PRInt32
) ZIP_OpenArchive( const char * zipname
, void** hZip
);
71 PR_EXTERN(PRInt32
) ZIP_CloseArchive( void** hZip
);
74 /* Test the integrity of every item in this open archive
75 * by verifying each item's checksum against the stored
78 PR_EXTERN(PRInt32
) ZIP_TestArchive( void* hZip
);
80 /* Extract the named file in the archive to disk.
81 * This function will happily overwrite an existing Outfile if it can.
82 * It's up to the caller to detect or move it out of the way if it's important.
84 PR_EXTERN(PRInt32
) ZIP_ExtractFile( void* hZip
, const char * filename
, const char * outname
);
87 /* Functions to list the files contained in the archive
89 * FindInit() initializes the search with the pattern and returns a find token,
90 * or NULL on an error. Then FindNext() is called with the token to get the
91 * matching filenames if any. When done you must call FindFree() with the
92 * token to release memory.
94 * a NULL pattern will find all the files in the archive, otherwise the
95 * pattern must be a shell regexp type pattern.
97 * if a matching filename is too small for the passed buffer FindNext()
98 * will return ZIP_ERR_SMALLBUF. When no more matches can be found in
99 * the archive it will return ZIP_ERR_FNF
101 PR_EXTERN(void*) ZIP_FindInit( void* hZip
, const char * pattern
);
102 PR_EXTERN(PRInt32
) ZIP_FindNext( void* hFind
, char * outbuf
, PRUint16 bufsize
);
103 PR_EXTERN(PRInt32
) ZIP_FindFree( void* hFind
);
110 #define ZIP_ERR_MEMORY NS_ERROR_OUT_OF_MEMORY
111 #define ZIP_ERR_DISK NS_ERROR_FILE_DISK_FULL
112 #define ZIP_ERR_CORRUPT NS_ERROR_FILE_CORRUPTED
113 #define ZIP_ERR_PARAM NS_ERROR_ILLEGAL_VALUE
114 #define ZIP_ERR_FNF NS_ERROR_FILE_TARGET_DOES_NOT_EXIST
115 #define ZIP_ERR_UNSUPPORTED NS_ERROR_NOT_IMPLEMENTED
116 #define ZIP_ERR_GENERAL NS_ERROR_FAILURE
118 #endif /* STANDALONE */
120 #endif /* _zipfile_h */