| Mike Lockwood | f99ad11 | 2013-10-03 10:29:39 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2007 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 | // | 
|  | 18 | // Miscellaneous zip/gzip utility functions. | 
|  | 19 | // | 
|  | 20 | #ifndef __LIBS_ZIPUTILS_H | 
|  | 21 | #define __LIBS_ZIPUTILS_H | 
|  | 22 |  | 
|  | 23 | #include <stdio.h> | 
|  | 24 |  | 
|  | 25 | namespace android { | 
|  | 26 |  | 
|  | 27 | /* | 
|  | 28 | * Container class for utility functions, primarily for namespace reasons. | 
|  | 29 | */ | 
|  | 30 | class ZipUtils { | 
|  | 31 | public: | 
|  | 32 | /* | 
|  | 33 | * General utility function for uncompressing "deflate" data from a file | 
|  | 34 | * to a buffer. | 
|  | 35 | */ | 
|  | 36 | static bool inflateToBuffer(int fd, void* buf, long uncompressedLen, | 
|  | 37 | long compressedLen); | 
|  | 38 | static bool inflateToBuffer(FILE* fp, void* buf, long uncompressedLen, | 
|  | 39 | long compressedLen); | 
|  | 40 |  | 
|  | 41 | /* | 
|  | 42 | * Someday we might want to make this generic and handle bzip2 ".bz2" | 
|  | 43 | * files too. | 
|  | 44 | * | 
|  | 45 | * We could declare gzip to be a sub-class of zip that has exactly | 
|  | 46 | * one always-compressed entry, but we currently want to treat Zip | 
|  | 47 | * and gzip as distinct, so there's no value. | 
|  | 48 | * | 
|  | 49 | * The zlib library has some gzip utilities, but it has no interface | 
|  | 50 | * for extracting the uncompressed length of the file (you do *not* | 
|  | 51 | * want to gzseek to the end). | 
|  | 52 | * | 
|  | 53 | * Pass in a seeked file pointer for the gzip file.  If this is a gzip | 
|  | 54 | * file, we set our return values appropriately and return "true" with | 
|  | 55 | * the file seeked to the start of the compressed data. | 
|  | 56 | */ | 
|  | 57 | static bool examineGzip(FILE* fp, int* pCompressionMethod, | 
|  | 58 | long* pUncompressedLen, long* pCompressedLen, unsigned long* pCRC32); | 
|  | 59 |  | 
|  | 60 | private: | 
|  | 61 | ZipUtils() {} | 
|  | 62 | ~ZipUtils() {} | 
|  | 63 | }; | 
|  | 64 |  | 
|  | 65 | }; // namespace android | 
|  | 66 |  | 
|  | 67 | #endif /*__LIBS_ZIPUTILS_H*/ |