1*387f9dfdSAndroid Build Coastguard Worker /* 2*387f9dfdSAndroid Build Coastguard Worker * Copyright (c) Meta Platforms, Inc. and affiliates. 3*387f9dfdSAndroid Build Coastguard Worker * 4*387f9dfdSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*387f9dfdSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*387f9dfdSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*387f9dfdSAndroid Build Coastguard Worker * 8*387f9dfdSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*387f9dfdSAndroid Build Coastguard Worker * 10*387f9dfdSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*387f9dfdSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*387f9dfdSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*387f9dfdSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*387f9dfdSAndroid Build Coastguard Worker * limitations under the License. 15*387f9dfdSAndroid Build Coastguard Worker */ 16*387f9dfdSAndroid Build Coastguard Worker 17*387f9dfdSAndroid Build Coastguard Worker #ifndef LIBBCC_ZIP_H 18*387f9dfdSAndroid Build Coastguard Worker #define LIBBCC_ZIP_H 19*387f9dfdSAndroid Build Coastguard Worker 20*387f9dfdSAndroid Build Coastguard Worker #include <stdint.h> 21*387f9dfdSAndroid Build Coastguard Worker 22*387f9dfdSAndroid Build Coastguard Worker #ifdef __cplusplus 23*387f9dfdSAndroid Build Coastguard Worker extern "C" { 24*387f9dfdSAndroid Build Coastguard Worker #endif 25*387f9dfdSAndroid Build Coastguard Worker 26*387f9dfdSAndroid Build Coastguard Worker // Represents an opened zip archive. 27*387f9dfdSAndroid Build Coastguard Worker // Only basic ZIP files are supported, in particular the following are not 28*387f9dfdSAndroid Build Coastguard Worker // supported: 29*387f9dfdSAndroid Build Coastguard Worker // - encryption 30*387f9dfdSAndroid Build Coastguard Worker // - streaming 31*387f9dfdSAndroid Build Coastguard Worker // - multi-part ZIP files 32*387f9dfdSAndroid Build Coastguard Worker // - ZIP64 33*387f9dfdSAndroid Build Coastguard Worker struct bcc_zip_archive; 34*387f9dfdSAndroid Build Coastguard Worker 35*387f9dfdSAndroid Build Coastguard Worker // Carries information on name, compression method and data corresponding to 36*387f9dfdSAndroid Build Coastguard Worker // a file in a zip archive. 37*387f9dfdSAndroid Build Coastguard Worker struct bcc_zip_entry { 38*387f9dfdSAndroid Build Coastguard Worker // Compression method as defined in pkzip spec. 0 means data is uncompressed. 39*387f9dfdSAndroid Build Coastguard Worker uint16_t compression; 40*387f9dfdSAndroid Build Coastguard Worker 41*387f9dfdSAndroid Build Coastguard Worker // Non-null terminated name of the file. 42*387f9dfdSAndroid Build Coastguard Worker const char* name; 43*387f9dfdSAndroid Build Coastguard Worker // Length of the file name. 44*387f9dfdSAndroid Build Coastguard Worker uint16_t name_length; 45*387f9dfdSAndroid Build Coastguard Worker 46*387f9dfdSAndroid Build Coastguard Worker // Pointer to the file data. 47*387f9dfdSAndroid Build Coastguard Worker const void* data; 48*387f9dfdSAndroid Build Coastguard Worker // Length of the file data. 49*387f9dfdSAndroid Build Coastguard Worker uint32_t data_length; 50*387f9dfdSAndroid Build Coastguard Worker // Offset of the file data within the archive. 51*387f9dfdSAndroid Build Coastguard Worker uint32_t data_offset; 52*387f9dfdSAndroid Build Coastguard Worker }; 53*387f9dfdSAndroid Build Coastguard Worker 54*387f9dfdSAndroid Build Coastguard Worker // Opens a zip archive. Returns NULL in case of an error. 55*387f9dfdSAndroid Build Coastguard Worker struct bcc_zip_archive* bcc_zip_archive_open(const char* path); 56*387f9dfdSAndroid Build Coastguard Worker 57*387f9dfdSAndroid Build Coastguard Worker // Closes a zip archive and releases resources. 58*387f9dfdSAndroid Build Coastguard Worker void bcc_zip_archive_close(struct bcc_zip_archive* archive); 59*387f9dfdSAndroid Build Coastguard Worker 60*387f9dfdSAndroid Build Coastguard Worker // Looks up data corresponding to a file in given zip archive. 61*387f9dfdSAndroid Build Coastguard Worker int bcc_zip_archive_find_entry(struct bcc_zip_archive* archive, 62*387f9dfdSAndroid Build Coastguard Worker const char* name, struct bcc_zip_entry* out); 63*387f9dfdSAndroid Build Coastguard Worker 64*387f9dfdSAndroid Build Coastguard Worker int bcc_zip_archive_find_entry_at_offset(struct bcc_zip_archive* archive, 65*387f9dfdSAndroid Build Coastguard Worker uint32_t offset, 66*387f9dfdSAndroid Build Coastguard Worker struct bcc_zip_entry* out); 67*387f9dfdSAndroid Build Coastguard Worker 68*387f9dfdSAndroid Build Coastguard Worker // Opens a zip archives and looks up entry within the archive. 69*387f9dfdSAndroid Build Coastguard Worker // Provided path is interpreted as archive path followed by "!/" 70*387f9dfdSAndroid Build Coastguard Worker // characters and name of the zip entry. This convention is used 71*387f9dfdSAndroid Build Coastguard Worker // by Android tools. 72*387f9dfdSAndroid Build Coastguard Worker struct bcc_zip_archive* bcc_zip_archive_open_and_find( 73*387f9dfdSAndroid Build Coastguard Worker const char* path, struct bcc_zip_entry* out); 74*387f9dfdSAndroid Build Coastguard Worker 75*387f9dfdSAndroid Build Coastguard Worker #ifdef __cplusplus 76*387f9dfdSAndroid Build Coastguard Worker } 77*387f9dfdSAndroid Build Coastguard Worker #endif 78*387f9dfdSAndroid Build Coastguard Worker #endif 79