1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
3
/* ***** BEGIN LICENSE BLOCK *****
4
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 1.1 (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
9
* http://www.mozilla.org/MPL/
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
16
* The Original Code is Mozilla Archive code.
18
* The Initial Developer of the Original Code is Google Inc.
19
* Portions created by the Initial Developer are Copyright (C) 2005
20
* the Initial Developer. All Rights Reserved.
23
* Darin Fisher <darin@meer.net>
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the MPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the MPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
42
/* We use NSPR here just to import the definition of PRUint32 */
50
* The MAR item data structure.
52
typedef struct MarItem_ {
53
struct MarItem_ *next; /* private field */
54
PRUint32 offset; /* offset into archive */
55
PRUint32 length; /* length of data in bytes */
56
PRUint32 flags; /* contains file mode bits */
57
char name[1]; /* file path */
60
typedef struct MarFile_ MarFile;
63
* Signature of callback function passed to mar_enum_items.
64
* @param mar The MAR file being visited.
65
* @param item The MAR item being visited.
66
* @param data The data parameter passed by the caller of mar_enum_items.
67
* @returns A non-zero value to stop enumerating.
69
typedef int (* MarItemCallback)(MarFile *mar, const MarItem *item, void *data);
72
* Open a MAR file for reading.
73
* @param path Specifies the path to the MAR file to open. This path must
74
* be compatible with fopen.
75
* @returns NULL if an error occurs.
77
MarFile *mar_open(const char *path);
80
* Close a MAR file that was opened using mar_open.
81
* @param mar The MarFile object to close.
83
void mar_close(MarFile *mar);
86
* Find an item in the MAR file by name.
87
* @param mar The MarFile object to query.
88
* @param item The name of the item to query.
89
* @returns A const reference to a MAR item or NULL if not found.
91
const MarItem *mar_find_item(MarFile *mar, const char *item);
94
* Enumerate all MAR items via callback function.
95
* @param mar The MAR file to enumerate.
96
* @param callback The function to call for each MAR item.
97
* @param data A caller specified value that is passed along to the
99
* @returns Zero if the enumeration ran to completion. Otherwise, any
100
* non-zero return value from the callback is returned.
102
int mar_enum_items(MarFile *mar, MarItemCallback callback, void *data);
105
* Read from MAR item at given offset up to bufsize bytes.
106
* @param mar The MAR file to read.
107
* @param item The MAR item to read.
108
* @param offset The byte offset relative to the start of the item.
109
* @param buf A pointer to a buffer to copy the data into.
110
* @param bufsize The length of the buffer to copy the data into.
111
* @returns The number of bytes written or a negative value if an
114
int mar_read(MarFile *mar, const MarItem *item, int offset, char *buf,
118
* Create a MAR file from a set of files.
119
* @param dest The path to the file to create. This path must be
120
* compatible with fopen.
121
* @param numfiles The number of files to store in the archive.
122
* @param files The list of null-terminated file paths. Each file
123
* path must be compatible with fopen.
124
* @returns A non-zero value if an error occurs.
126
int mar_create(const char *dest, int numfiles, char **files);
129
* Extract a MAR file to the current working directory.
130
* @param path The path to the MAR file to extract. This path must be
131
* compatible with fopen.
132
* @returns A non-zero value if an error occurs.
134
int mar_extract(const char *path);