13344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian/*
23344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Copyright (C) 2006 The Android Open Source Project
33344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
43344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
53344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * you may not use this file except in compliance with the License.
63344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * You may obtain a copy of the License at
73344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
83344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
93344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
103344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Unless required by applicable law or agreed to in writing, software
113344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
123344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * See the License for the specific language governing permissions and
143344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * limitations under the License.
153344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */
163344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
173344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian//
183344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian// General-purpose Zip archive access.  This class allows both reading and
193344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian// writing to Zip archives, including deletion of existing entries.
203344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian//
213344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#ifndef __LIBS_ZIPFILE_H
223344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#define __LIBS_ZIPFILE_H
233344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
243344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#include <utils/Vector.h>
253344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#include <utils/Errors.h>
263344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#include <stdio.h>
273344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
283344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#include "ZipEntry.h"
293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
303344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopiannamespace android {
313344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
323344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian/*
333344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Manipulate a Zip archive.
343344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
353344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Some changes will not be visible in the until until "flush" is called.
363344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
373344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * The correct way to update a file archive is to make all changes to a
383344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * copy of the archive in a temporary file, and then unlink/rename over
393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * the original after everything completes.  Because we're only interested
403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * in using this for packaging, we don't worry about such things.  Crashing
413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * after making changes and before flush() completes could leave us with
423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * an unusable Zip archive.
433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */
443344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianclass ZipFile {
453344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianpublic:
463344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ZipFile(void)
473344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian      : mZipFp(NULL), mReadOnly(false), mNeedCDRewrite(false)
483344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian      {}
493344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ~ZipFile(void) {
503344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        if (!mReadOnly)
513344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            flush();
523344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        if (mZipFp != NULL)
533344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            fclose(mZipFp);
543344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        discardEntries();
553344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
563344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
573344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
583344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Open a new or existing archive.
593344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
601022e27642a891550742013e9a12bc1256429a69Glenn Kasten    enum {
613344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kOpenReadOnly   = 0x01,
623344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kOpenReadWrite  = 0x02,
633344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kOpenCreate     = 0x04,     // create if it doesn't exist
643344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kOpenTruncate   = 0x08,     // if it exists, empty it
653344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    };
663344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t open(const char* zipFileName, int flags);
673344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
683344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
693344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Add a file to the end of the archive.  Specify whether you want the
703344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * library to try to store it compressed.
713344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     *
723344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * If "storageName" is specified, the archive will use that instead
733344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * of "fileName".
743344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     *
753344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * If there is already an entry with the same name, the call fails.
763344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Existing entries with the same name must be removed first.
773344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     *
783344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
793344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
80b589ae4e2661d42cbdc0a44193e2df384424e483Dan Willemsen    status_t add(const char* fileName, int compressionMethod,
813344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        ZipEntry** ppEntry)
823344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    {
83b589ae4e2661d42cbdc0a44193e2df384424e483Dan Willemsen        return add(fileName, fileName, compressionMethod, ppEntry);
843344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
853344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t add(const char* fileName, const char* storageName,
86b589ae4e2661d42cbdc0a44193e2df384424e483Dan Willemsen        int compressionMethod, ZipEntry** ppEntry)
873344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    {
883344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        return addCommon(fileName, NULL, 0, storageName,
89b589ae4e2661d42cbdc0a44193e2df384424e483Dan Willemsen                         compressionMethod, ppEntry);
903344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
913344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
923344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
933344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Add a file from an in-memory data buffer.
943344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     *
953344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
963344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
973344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t add(const void* data, size_t size, const char* storageName,
98b589ae4e2661d42cbdc0a44193e2df384424e483Dan Willemsen        int compressionMethod, ZipEntry** ppEntry)
993344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    {
1003344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        return addCommon(NULL, data, size, storageName,
101b589ae4e2661d42cbdc0a44193e2df384424e483Dan Willemsen                         compressionMethod, ppEntry);
1023344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
1033344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1043344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1053344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Add an entry by copying it from another zip file.  If "padding" is
1063344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * nonzero, the specified number of bytes will be added to the "extra"
1073344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * field in the header.
1083344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     *
1093344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
1103344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1113344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
112b589ae4e2661d42cbdc0a44193e2df384424e483Dan Willemsen        int padding, ZipEntry** ppEntry);
1133344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1143344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
115093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien     * Add an entry by copying it from another zip file, recompressing with
116093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien     * Zopfli if already compressed.
117093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien     *
118093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
119093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien     */
120093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien    status_t addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
121b589ae4e2661d42cbdc0a44193e2df384424e483Dan Willemsen        ZipEntry** ppEntry);
122093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien
123093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien    /*
1243344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Mark an entry as having been removed.  It is not actually deleted
1253344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * from the archive or our internal data structures until flush() is
1263344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * called.
1273344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1283344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t remove(ZipEntry* pEntry);
1293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1303344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1313344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Flush changes.  If mNeedCDRewrite is set, this writes the central dir.
1323344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1333344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t flush(void);
1343344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1353344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1363344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Expand the data into the buffer provided.  The buffer must hold
1373344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * at least <uncompressed len> bytes.  Variation expands directly
1383344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * to a file.
1393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     *
1403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Returns "false" if an error was encountered in the compressed data.
1413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    //bool uncompress(const ZipEntry* pEntry, void* buf) const;
1433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    //bool uncompress(const ZipEntry* pEntry, FILE* fp) const;
144093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien    void* uncompress(const ZipEntry* pEntry) const;
1453344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1463344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1473344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Get an entry, by name.  Returns NULL if not found.
1483344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     *
1493344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Does not return entries pending deletion.
1503344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1513344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ZipEntry* getEntryByName(const char* fileName) const;
1523344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1533344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1543344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Get the Nth entry in the archive.
1553344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     *
1563344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * This will return an entry that is pending deletion.
1573344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1583344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    int getNumEntries(void) const { return mEntries.size(); }
1593344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ZipEntry* getEntryByIndex(int idx) const;
1603344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1613344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianprivate:
1623344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* these are private and not defined */
1633344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ZipFile(const ZipFile& src);
1643344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ZipFile& operator=(const ZipFile& src);
1653344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1663344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    class EndOfCentralDir {
1673344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    public:
1683344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        EndOfCentralDir(void) :
1693344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mDiskNumber(0),
1703344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mDiskWithCentralDir(0),
1713344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mNumEntries(0),
1723344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mTotalNumEntries(0),
1733344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCentralDirSize(0),
1743344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCentralDirOffset(0),
1753344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCommentLen(0),
1763344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mComment(NULL)
1773344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            {}
1783344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        virtual ~EndOfCentralDir(void) {
1793344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            delete[] mComment;
1803344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        }
1813344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
18241bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        status_t readBuf(const uint8_t* buf, int len);
1833344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        status_t write(FILE* fp);
1843344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
18541bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        //uint32_t mSignature;
18641bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mDiskNumber;
18741bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mDiskWithCentralDir;
18841bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mNumEntries;
18941bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mTotalNumEntries;
19041bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mCentralDirSize;
19141bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mCentralDirOffset;      // offset from first disk
19241bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mCommentLen;
19341bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint8_t* mComment;
1943344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1953344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        enum {
1963344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            kSignature      = 0x06054b50,
1973344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            kEOCDLen        = 22,       // EndOfCentralDir len, excl. comment
1983344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1993344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            kMaxCommentLen  = 65535,    // longest possible in ushort
2003344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            kMaxEOCDSearch  = kMaxCommentLen + EndOfCentralDir::kEOCDLen,
2013344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2023344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        };
2033344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2043344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        void dump(void) const;
2053344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    };
2063344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2073344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2083344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* read all entries in the central dir */
2093344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t readCentralDir(void);
2103344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2113344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* crunch deleted entries out */
2123344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t crunchArchive(void);
2133344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2143344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* clean up mEntries */
2153344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    void discardEntries(void);
2163344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2173344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* common handler for all "add" functions */
2183344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t addCommon(const char* fileName, const void* data, size_t size,
219b46507ff9eba4266e9db4eb2bb7f0b6ad4483892Narayan Kamath        const char* storageName, int compressionMethod, ZipEntry** ppEntry);
2203344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2213344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* copy all of "srcFp" into "dstFp" */
22241bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen    status_t copyFpToFp(FILE* dstFp, FILE* srcFp, uint32_t* pCRC32);
2233344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* copy all of "data" into "dstFp" */
2243344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t copyDataToFp(FILE* dstFp,
22541bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        const void* data, size_t size, uint32_t* pCRC32);
2263344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* copy some of "srcFp" into "dstFp" */
2273344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
22841bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t* pCRC32);
2293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* like memmove(), but on parts of a single file */
2303344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t filemove(FILE* fp, off_t dest, off_t src, size_t n);
2313344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* compress all of "srcFp" into "dstFp", using Deflate */
2323344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t compressFpToFp(FILE* dstFp, FILE* srcFp,
23341bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        const void* data, size_t size, uint32_t* pCRC32);
2343344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2353344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* get modification date from a file descriptor */
2363344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    time_t getModTime(int fd);
2373344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2383344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
2393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * We use stdio FILE*, which gives us buffering but makes dealing
2403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * with files >2GB awkward.  Until we support Zip64, we're fine.
2413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
2423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    FILE*           mZipFp;             // Zip file pointer
2433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2443344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* one of these per file */
2453344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    EndOfCentralDir mEOCD;
2463344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2473344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* did we open this read-only? */
2483344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    bool            mReadOnly;
2493344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2503344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* set this when we trash the central dir */
2513344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    bool            mNeedCDRewrite;
2523344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2533344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
2543344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * One ZipEntry per entry in the zip file.  I'm using pointers instead
2553344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * of objects because it's easier than making operator= work for the
2563344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * classes and sub-classes.
2573344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
2583344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    Vector<ZipEntry*>   mEntries;
2593344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian};
2603344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2613344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian}; // namespace android
2623344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2633344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#endif // __LIBS_ZIPFILE_H
264