Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jan 1996 09:13:05 -0800
From:      "Jordan K. Hubbard" <jkh@time.cdrom.com>
To:        Nate Williams <nate@sri.MT.net>
Cc:        Michael Smith <msmith@atrad.adelaide.edu.au>, tnaggs@cddotdot.mikom.csir.co.za, Hackers@freebsd.org
Subject:   Re: FBSD 2.1 
Message-ID:  <10575.821812385@time.cdrom.com>
In-Reply-To: Your message of "Tue, 16 Jan 1996 08:47:13 MST." <199601161547.IAA04366@rocky.sri.MT.net> 

next in thread | previous in thread | raw e-mail | index | archive | help
Ok, you wanted a library API, how about this one?

Where ZIP_t is an opaque type:


ZIP_t	zip_init(int fd)

Returns ZIP file handle for already open fd, or NULL on failure.  fd
should be open for reading, at a minimum, and positioned at the
beginning of the file.


int	zip_options(ZIP_t zp, int opts)

Used to set things like compression levels, whether existing entries
are replaced by default, etc.  I'll leave the definition of `opts' to
the implementor.


int	zip_add(ZIP_t zp, char *fname, int link)

Add file fname to zip file (which must be writable).
If fname is a link and link is true, the link will be stored
as a link, otherwise what it points to will be stored.
[I don't know if you want to also do a version which will add directly
 from a fd - it seems like it'd be cute, but I can't think of any
 immediate uses :-)]
Return 0 on success, -1 if file non-existant, -2 if permission denied.


int	zip_delete(ZIP_t zp, char *fname)

Delete entry named fname from the zip file.
Return 0 on success, -1 if file non-existant, -2 if permission denied.


int	zip_test(ZIP_t zp)

Returns 0 if zip file passes internal consistency checks, an internal
error code (defined as the set of meaningful condition codes zip can
generate, I guess) if not.


int	zip_dir(ZIP_t zp, int *nitems, char ***list)

Return table of contents for zip file, using nitems and list values to
pass back the item count and array of char * pointers holding the
filenames.  Return 0 on success, -1 on failure.  User is expected to
free contents of list when done with it.


int	zip_attrs(ZIP_t zp, char *fname, ZIP_file_attrs *attrs)

Returns `long' file attributes for a given file, returning the result
in the public structure `attrs'.  I'm not sure what fields are
available in a zip file header, but I'd imagine this being stuff like
the creation date, length, etc.  Returns 0 on success, -1 on error.


int	zip_fdopen(ZIP_t zp, char *fname)

Return a file descriptor for an entry in a zip file.  When a read from
the new fd returns EOF, a zip_close() on the fd should be done to
clean up any state lying around.
Returns new fd on success or -1 if entry not found/open failed.


int	zip_fdclose(ZIP_t zp, int fd)

Close a file descriptor previously returned by zip_open().
Returns 0 on success, -1 on error.


char	*zip_read(ZIP_t zp, char *fname)

Return an entry in a zip file as a single string.  User is expected
to free storage when done with it.  Returns NULL if file could not be
found or sufficient memory could not be allocated.


int	zip_close(ZIP_t zp)

Close a zip file and any open resources.  This will also invalidate
any open handles returned by zip_fdopen().


That should handle just about all the major contingencies that I can
think of..  Any major holes in my reasoning anyone can see here?

					Jordan



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?10575.821812385>