zip_archive.h revision a2806550cefb7c70781d8ee6279e6ad5769804cb
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ART_RUNTIME_ZIP_ARCHIVE_H_ 18#define ART_RUNTIME_ZIP_ARCHIVE_H_ 19 20#include <stdint.h> 21#include <string> 22#include <ziparchive/zip_archive.h> 23 24#include "base/logging.h" 25#include "base/unix_file/random_access_file.h" 26#include "globals.h" 27#include "mem_map.h" 28#include "os.h" 29#include "safe_map.h" 30#include "UniquePtr.h" 31 32namespace art { 33 34class ZipArchive; 35class MemMap; 36 37class ZipEntry { 38 public: 39 bool ExtractToFile(File& file, std::string* error_msg); 40 MemMap* ExtractToMemMap(const char* entry_filename, std::string* error_msg); 41 42 uint32_t GetUncompressedLength(); 43 uint32_t GetCrc32(); 44 45 private: 46 ZipEntry(ZipArchiveHandle handle, 47 ::ZipEntry* zip_entry) : handle_(handle), zip_entry_(zip_entry) {} 48 49 ZipArchiveHandle handle_; 50 ::ZipEntry* const zip_entry_; 51 52 friend class ZipArchive; 53 DISALLOW_COPY_AND_ASSIGN(ZipEntry); 54}; 55 56class ZipArchive { 57 public: 58 // return new ZipArchive instance on success, NULL on error. 59 static ZipArchive* Open(const char* filename, std::string* error_msg); 60 static ZipArchive* OpenFromFd(int fd, const char* filename, std::string* error_msg); 61 62 ZipEntry* Find(const char* name, std::string* error_msg) const; 63 64 ~ZipArchive() { 65 CloseArchive(handle_); 66 } 67 68 private: 69 explicit ZipArchive(ZipArchiveHandle handle) : handle_(handle) {} 70 71 friend class ZipEntry; 72 73 ZipArchiveHandle handle_; 74 75 DISALLOW_COPY_AND_ASSIGN(ZipArchive); 76}; 77 78} // namespace art 79 80#endif // ART_RUNTIME_ZIP_ARCHIVE_H_ 81