2006-02-11 23:49:09 +01:00
|
|
|
// archive backend for Zip files
|
|
|
|
//
|
|
|
|
// Copyright (c) 2003-2006 Jan Wassenberg
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// Contact info:
|
|
|
|
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
// http://www.stud.uni-karlsruhe.de/~urkt/
|
|
|
|
|
2004-07-31 13:03:17 +02:00
|
|
|
#ifndef ZIP_H__
|
|
|
|
#define ZIP_H__
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2006-02-11 23:49:09 +01:00
|
|
|
struct File;
|
|
|
|
struct Archive;
|
|
|
|
struct ArchiveEntry;
|
|
|
|
|
|
|
|
|
|
|
|
// analyse an opened file: if it is a Zip archive, call back into
|
|
|
|
// archive.cpp to populate the Archive object with a list of the
|
|
|
|
// files it contains.
|
|
|
|
// returns ERR_OK on success, ERR_UNKNOWN_FORMAT if not a Zip archive
|
|
|
|
// (see below) or another negative LibError code.
|
|
|
|
//
|
|
|
|
// fairly slow - must read Central Directory from disk
|
|
|
|
// (size ~= 60 bytes*num_files); observed time ~= 80ms.
|
|
|
|
extern LibError zip_populate_archive(File* f, Archive* a);
|
2004-08-24 19:29:54 +02:00
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2006-02-11 23:49:09 +01:00
|
|
|
// ensures <ent.ofs> points to the actual file contents; it is initially
|
|
|
|
// the offset of the LFH. we cannot use CDFH filename and extra field
|
|
|
|
// lengths to skip past LFH since that may not mirror CDFH (has happened).
|
|
|
|
//
|
|
|
|
// this is called at file-open time instead of while mounting to
|
|
|
|
// reduce seeks: since reading the file will typically follow, the
|
|
|
|
// block cache entirely absorbs the IO cost.
|
2006-01-23 21:05:09 +01:00
|
|
|
extern void zip_fixup_lfh(File* f, ArchiveEntry* ent);
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2006-01-28 23:19:42 +01:00
|
|
|
|
2006-02-11 23:49:09 +01:00
|
|
|
//
|
|
|
|
// archive builder backend
|
|
|
|
//
|
|
|
|
|
|
|
|
struct ZipArchive; // opaque
|
|
|
|
|
2006-02-15 04:03:17 +01:00
|
|
|
// create a new Zip archive and return a pointer for use in subsequent
|
|
|
|
// zip_archive_add_file calls. previous archive file is overwritten.
|
2006-01-28 23:19:42 +01:00
|
|
|
extern LibError zip_archive_create(const char* zip_filename, ZipArchive** pza);
|
2006-02-15 04:03:17 +01:00
|
|
|
|
|
|
|
// add a file (described by ArchiveEntry) to the archive. file_contents
|
|
|
|
// is the actual file data; its compression method is given in ae->method and
|
|
|
|
// can be CM_NONE.
|
|
|
|
// IO cost: writes out <file_contents> to disk (we don't currently attempt
|
|
|
|
// any sort of write-buffering).
|
2006-02-11 23:49:09 +01:00
|
|
|
extern LibError zip_archive_add_file(ZipArchive* za, const ArchiveEntry* ae, void* file_contents);
|
2006-02-15 04:03:17 +01:00
|
|
|
|
|
|
|
// write out the archive to disk; only hereafter is it valid.
|
|
|
|
// frees the ZipArchive instance.
|
|
|
|
// IO cost: writes out Central Directory to disk (about 70 bytes per file).
|
2006-01-28 23:19:42 +01:00
|
|
|
extern LibError zip_archive_finish(ZipArchive* za);
|
|
|
|
|
|
|
|
|
2004-07-31 13:03:17 +02:00
|
|
|
#endif // #ifndef ZIP_H__
|