mirror of
https://github.com/QuasarApp/zip.git
synced 2025-04-26 04:34:31 +00:00
forward changes we use in ogre (#242)
* allow access to the file compressed size * option for case-sensitive operation * refactor naming Co-authored-by: Kuba Podgórski <kuba--@users.noreply.github.com>
This commit is contained in:
parent
3229b037a1
commit
7789dcbfd5
24
src/zip.c
24
src/zip.c
@ -885,7 +885,8 @@ int zip_is64(struct zip_t *zip) {
|
||||
return (int)zip->archive.m_pState->m_zip64;
|
||||
}
|
||||
|
||||
int zip_entry_open(struct zip_t *zip, const char *entryname) {
|
||||
static int _zip_entry_open(struct zip_t *zip, const char *entryname,
|
||||
int case_sensitive) {
|
||||
size_t entrylen = 0;
|
||||
mz_zip_archive *pzip = NULL;
|
||||
mz_uint num_alignment_padding_bytes, level;
|
||||
@ -938,8 +939,9 @@ int zip_entry_open(struct zip_t *zip, const char *entryname) {
|
||||
|
||||
pzip = &(zip->archive);
|
||||
if (pzip->m_zip_mode == MZ_ZIP_MODE_READING) {
|
||||
zip->entry.index =
|
||||
mz_zip_reader_locate_file(pzip, zip->entry.name, NULL, 0);
|
||||
zip->entry.index = mz_zip_reader_locate_file(
|
||||
pzip, zip->entry.name, NULL,
|
||||
case_sensitive ? MZ_ZIP_FLAG_CASE_SENSITIVE : 0);
|
||||
if (zip->entry.index < 0) {
|
||||
err = ZIP_ENOENT;
|
||||
goto cleanup;
|
||||
@ -1083,6 +1085,14 @@ cleanup:
|
||||
return err;
|
||||
}
|
||||
|
||||
int zip_entry_open(struct zip_t *zip, const char *entryname) {
|
||||
return _zip_entry_open(zip, entryname, 0);
|
||||
}
|
||||
|
||||
int zip_entry_opencasesensitive(struct zip_t *zip, const char *entryname) {
|
||||
return _zip_entry_open(zip, entryname, 1);
|
||||
}
|
||||
|
||||
int zip_entry_openbyindex(struct zip_t *zip, int index) {
|
||||
mz_zip_archive *pZip = NULL;
|
||||
mz_zip_archive_file_stat stats;
|
||||
@ -1290,9 +1300,17 @@ int zip_entry_isdir(struct zip_t *zip) {
|
||||
}
|
||||
|
||||
unsigned long long zip_entry_size(struct zip_t *zip) {
|
||||
return zip_entry_uncomp_size(zip);
|
||||
}
|
||||
|
||||
unsigned long long zip_entry_uncomp_size(struct zip_t *zip) {
|
||||
return zip ? zip->entry.uncomp_size : 0;
|
||||
}
|
||||
|
||||
unsigned long long zip_entry_comp_size(struct zip_t *zip) {
|
||||
return zip ? zip->entry.comp_size : 0;
|
||||
}
|
||||
|
||||
unsigned int zip_entry_crc32(struct zip_t *zip) {
|
||||
return zip ? zip->entry.uncomp_crc32 : 0;
|
||||
}
|
||||
|
36
src/zip.h
36
src/zip.h
@ -159,6 +159,21 @@ extern ZIP_EXPORT int zip_is64(struct zip_t *zip);
|
||||
*/
|
||||
extern ZIP_EXPORT int zip_entry_open(struct zip_t *zip, const char *entryname);
|
||||
|
||||
/**
|
||||
* Opens an entry by name in the zip archive.
|
||||
*
|
||||
* For zip archive opened in 'w' or 'a' mode the function will append
|
||||
* a new entry. In readonly mode the function tries to locate the entry
|
||||
* in global dictionary (case sensitive).
|
||||
*
|
||||
* @param zip zip archive handler.
|
||||
* @param entryname an entry name in local dictionary (case sensitive).
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern ZIP_EXPORT int zip_entry_opencasesensitive(struct zip_t *zip,
|
||||
const char *entryname);
|
||||
|
||||
/**
|
||||
* Opens a new entry by index in the zip archive.
|
||||
*
|
||||
@ -216,7 +231,8 @@ extern ZIP_EXPORT int zip_entry_index(struct zip_t *zip);
|
||||
extern ZIP_EXPORT int zip_entry_isdir(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Returns an uncompressed size of the current zip entry.
|
||||
* Returns the uncompressed size of the current zip entry.
|
||||
* Alias for zip_entry_uncomp_size (for backward compatibility).
|
||||
*
|
||||
* @param zip zip archive handler.
|
||||
*
|
||||
@ -224,6 +240,24 @@ extern ZIP_EXPORT int zip_entry_isdir(struct zip_t *zip);
|
||||
*/
|
||||
extern ZIP_EXPORT unsigned long long zip_entry_size(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Returns the uncompressed size of the current zip entry.
|
||||
*
|
||||
* @param zip zip archive handler.
|
||||
*
|
||||
* @return the uncompressed size in bytes.
|
||||
*/
|
||||
extern ZIP_EXPORT unsigned long long zip_entry_uncomp_size(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Returns the compressed size of the current zip entry.
|
||||
*
|
||||
* @param zip zip archive handler.
|
||||
*
|
||||
* @return the compressed size in bytes.
|
||||
*/
|
||||
extern ZIP_EXPORT unsigned long long zip_entry_comp_size(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Returns CRC-32 checksum of the current zip entry.
|
||||
*
|
||||
|
@ -109,6 +109,22 @@ MU_TEST(test_entry_name) {
|
||||
zip_close(zip);
|
||||
}
|
||||
|
||||
MU_TEST(test_entry_opencasesensitive) {
|
||||
struct zip_t *zip = zip_open(ZIPNAME, 0, 'r');
|
||||
mu_check(zip != NULL);
|
||||
|
||||
mu_check(zip_entry_name(zip) == NULL);
|
||||
|
||||
mu_assert_int_eq(0, zip_entry_open(zip, "test/TEST-1.TXT"));
|
||||
mu_check(NULL != zip_entry_name(zip));
|
||||
mu_assert_int_eq(0, zip_entry_close(zip));
|
||||
|
||||
mu_assert_int_eq(ZIP_ENOENT,
|
||||
zip_entry_opencasesensitive(zip, "test/TEST-1.TXT"));
|
||||
|
||||
zip_close(zip);
|
||||
}
|
||||
|
||||
MU_TEST(test_entry_index) {
|
||||
struct zip_t *zip = zip_open(ZIPNAME, 0, 'r');
|
||||
mu_check(zip != NULL);
|
||||
@ -261,6 +277,7 @@ MU_TEST_SUITE(test_entry_suite) {
|
||||
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
|
||||
|
||||
MU_RUN_TEST(test_entry_name);
|
||||
MU_RUN_TEST(test_entry_opencasesensitive);
|
||||
MU_RUN_TEST(test_entry_index);
|
||||
MU_RUN_TEST(test_entry_openbyindex);
|
||||
MU_RUN_TEST(test_entry_read);
|
||||
|
Loading…
x
Reference in New Issue
Block a user