diff options
Diffstat (limited to 'include/ziparchive/zip_archive.h')
-rw-r--r-- | include/ziparchive/zip_archive.h | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/include/ziparchive/zip_archive.h b/include/ziparchive/zip_archive.h index 1877494..7da6e84 100644 --- a/include/ziparchive/zip_archive.h +++ b/include/ziparchive/zip_archive.h @@ -21,6 +21,7 @@ #define LIBZIPARCHIVE_ZIPARCHIVE_H_ #include <stdint.h> +#include <string.h> #include <sys/types.h> #include <utils/Compat.h> @@ -33,8 +34,16 @@ enum { }; struct ZipEntryName { - const char* name; + const uint8_t* name; uint16_t name_length; + + ZipEntryName() {} + + /* + * entry_name has to be an c-style string with only ASCII characters. + */ + explicit ZipEntryName(const char* entry_name) + : name(reinterpret_cast<const uint8_t*>(entry_name)), name_length(strlen(entry_name)) {} }; /* @@ -124,24 +133,24 @@ void CloseArchive(ZipArchiveHandle handle); * and length, a call to VerifyCrcAndLengths must be made after entry data * has been processed. */ -int32_t FindEntry(const ZipArchiveHandle handle, const char* entryName, +int32_t FindEntry(const ZipArchiveHandle handle, const ZipEntryName& entryName, ZipEntry* data); /* * Start iterating over all entries of a zip file. The order of iteration * is not guaranteed to be the same as the order of elements - * in the central directory but is stable for a given zip file. |cookie| - * must point to a writeable memory location, and will be set to the value - * of an opaque cookie which can be used to make one or more calls to - * Next. + * in the central directory but is stable for a given zip file. |cookie| will + * contain the value of an opaque cookie which can be used to make one or more + * calls to Next. All calls to StartIteration must be matched by a call to + * EndIteration to free any allocated memory. * * This method also accepts an optional prefix to restrict iteration to - * entry names that start with |prefix|. + * entry names that start with |optional_prefix|. * * Returns 0 on success and negative values on failure. */ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, - const char* prefix); + const ZipEntryName* optional_prefix); /* * Advance to the next element in the zipfile in iteration order. @@ -152,6 +161,12 @@ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, int32_t Next(void* cookie, ZipEntry* data, ZipEntryName *name); /* + * End iteration over all entries of a zip file and frees the memory allocated + * in StartIteration. + */ +void EndIteration(void* cookie); + +/* * Uncompress and write an entry to an open file identified by |fd|. * |entry->uncompressed_length| bytes will be written to the file at * its current offset, and the file will be truncated at the end of |