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 */ 803344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t add(const char* fileName, int compressionMethod, 813344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry** ppEntry) 823344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian { 833344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian return add(fileName, fileName, compressionMethod, ppEntry); 843344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian } 853344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t add(const char* fileName, const char* storageName, 863344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian int compressionMethod, ZipEntry** ppEntry) 873344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian { 883344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian return addCommon(fileName, NULL, 0, storageName, 893344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry::kCompressStored, 903344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian compressionMethod, ppEntry); 913344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian } 923344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 933344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 943344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Add a file that is already compressed with gzip. 953344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * 963344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * If "ppEntry" is non-NULL, a pointer to the new entry will be returned. 973344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 983344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t addGzip(const char* fileName, const char* storageName, 993344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry** ppEntry) 1003344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian { 1013344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian return addCommon(fileName, NULL, 0, storageName, 1023344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry::kCompressDeflated, 1033344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry::kCompressDeflated, ppEntry); 1043344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian } 1053344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1063344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 1073344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Add a file from an in-memory data buffer. 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 void* data, size_t size, const char* storageName, 1123344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian int compressionMethod, ZipEntry** ppEntry) 1133344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian { 1143344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian return addCommon(NULL, data, size, storageName, 1153344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry::kCompressStored, 1163344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian compressionMethod, ppEntry); 1173344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian } 1183344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1193344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 1203344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Add an entry by copying it from another zip file. If "padding" is 1213344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * nonzero, the specified number of bytes will be added to the "extra" 1223344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * field in the header. 1233344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * 1243344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * If "ppEntry" is non-NULL, a pointer to the new entry will be returned. 1253344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 1263344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry, 1273344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian int padding, ZipEntry** ppEntry); 1283344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 130093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien * Add an entry by copying it from another zip file, recompressing with 131093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien * Zopfli if already compressed. 132093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien * 133093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien * If "ppEntry" is non-NULL, a pointer to the new entry will be returned. 134093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien */ 135093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien status_t addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry, 136093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien ZipEntry** ppEntry); 137093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien 138093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien /* 1393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Mark an entry as having been removed. It is not actually deleted 1403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * from the archive or our internal data structures until flush() is 1413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * called. 1423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 1433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t remove(ZipEntry* pEntry); 1443344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1453344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 1463344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Flush changes. If mNeedCDRewrite is set, this writes the central dir. 1473344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 1483344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t flush(void); 1493344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1503344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 1513344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Expand the data into the buffer provided. The buffer must hold 1523344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * at least <uncompressed len> bytes. Variation expands directly 1533344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * to a file. 1543344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * 1553344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Returns "false" if an error was encountered in the compressed data. 1563344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 1573344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian //bool uncompress(const ZipEntry* pEntry, void* buf) const; 1583344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian //bool uncompress(const ZipEntry* pEntry, FILE* fp) const; 159093d04c631aa2a4af3317912e9561672c5642bb8Raph Levien void* uncompress(const ZipEntry* pEntry) const; 1603344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1613344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 1623344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Get an entry, by name. Returns NULL if not found. 1633344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * 1643344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Does not return entries pending deletion. 1653344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 1663344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry* getEntryByName(const char* fileName) const; 1673344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1683344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 1693344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Get the Nth entry in the archive. 1703344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * 1713344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * This will return an entry that is pending deletion. 1723344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 1733344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian int getNumEntries(void) const { return mEntries.size(); } 1743344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry* getEntryByIndex(int idx) const; 1753344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1763344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianprivate: 1773344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* these are private and not defined */ 1783344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipFile(const ZipFile& src); 1793344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipFile& operator=(const ZipFile& src); 1803344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1813344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian class EndOfCentralDir { 1823344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian public: 1833344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian EndOfCentralDir(void) : 1843344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian mDiskNumber(0), 1853344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian mDiskWithCentralDir(0), 1863344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian mNumEntries(0), 1873344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian mTotalNumEntries(0), 1883344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian mCentralDirSize(0), 1893344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian mCentralDirOffset(0), 1903344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian mCommentLen(0), 1913344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian mComment(NULL) 1923344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian {} 1933344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian virtual ~EndOfCentralDir(void) { 1943344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian delete[] mComment; 1953344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian } 1963344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 1973344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t readBuf(const unsigned char* buf, int len); 1983344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t write(FILE* fp); 1993344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2003344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian //unsigned long mSignature; 2013344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned short mDiskNumber; 2023344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned short mDiskWithCentralDir; 2033344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned short mNumEntries; 2043344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned short mTotalNumEntries; 2053344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned long mCentralDirSize; 2063344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned long mCentralDirOffset; // offset from first disk 2073344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned short mCommentLen; 2083344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned char* mComment; 2093344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2103344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian enum { 2113344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian kSignature = 0x06054b50, 2123344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian kEOCDLen = 22, // EndOfCentralDir len, excl. comment 2133344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2143344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian kMaxCommentLen = 65535, // longest possible in ushort 2153344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian kMaxEOCDSearch = kMaxCommentLen + EndOfCentralDir::kEOCDLen, 2163344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2173344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian }; 2183344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2193344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian void dump(void) const; 2203344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian }; 2213344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2223344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2233344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* read all entries in the central dir */ 2243344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t readCentralDir(void); 2253344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2263344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* crunch deleted entries out */ 2273344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t crunchArchive(void); 2283344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* clean up mEntries */ 2303344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian void discardEntries(void); 2313344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2323344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* common handler for all "add" functions */ 2333344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t addCommon(const char* fileName, const void* data, size_t size, 2343344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian const char* storageName, int sourceType, int compressionMethod, 2353344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian ZipEntry** ppEntry); 2363344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2373344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* copy all of "srcFp" into "dstFp" */ 2383344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32); 2393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* copy all of "data" into "dstFp" */ 2403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t copyDataToFp(FILE* dstFp, 2413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian const void* data, size_t size, unsigned long* pCRC32); 2423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* copy some of "srcFp" into "dstFp" */ 2433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length, 2443344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian unsigned long* pCRC32); 2453344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* like memmove(), but on parts of a single file */ 2463344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t filemove(FILE* fp, off_t dest, off_t src, size_t n); 2473344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* compress all of "srcFp" into "dstFp", using Deflate */ 2483344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian status_t compressFpToFp(FILE* dstFp, FILE* srcFp, 2493344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian const void* data, size_t size, unsigned long* pCRC32); 2503344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2513344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* get modification date from a file descriptor */ 2523344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian time_t getModTime(int fd); 2533344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2543344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 2553344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * We use stdio FILE*, which gives us buffering but makes dealing 2563344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * with files >2GB awkward. Until we support Zip64, we're fine. 2573344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 2583344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian FILE* mZipFp; // Zip file pointer 2593344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2603344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* one of these per file */ 2613344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian EndOfCentralDir mEOCD; 2623344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2633344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* did we open this read-only? */ 2643344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian bool mReadOnly; 2653344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2663344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* set this when we trash the central dir */ 2673344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian bool mNeedCDRewrite; 2683344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2693344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian /* 2703344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * One ZipEntry per entry in the zip file. I'm using pointers instead 2713344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * of objects because it's easier than making operator= work for the 2723344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * classes and sub-classes. 2733344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */ 2743344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian Vector<ZipEntry*> mEntries; 2753344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian}; 2763344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2773344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian}; // namespace android 2783344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian 2793344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#endif // __LIBS_ZIPFILE_H 280