Make tester and examples compile again and test script

This commit is contained in:
Martin
2016-11-27 21:39:02 +01:00
parent c06aa2da84
commit 55339a8978
6 changed files with 257 additions and 171 deletions

View File

@@ -32,6 +32,9 @@ add_executable(example5 ${EXAMPLE5_SRC_LIST})
target_link_libraries(example5 miniz) target_link_libraries(example5 miniz)
add_executable(example6 ${EXAMPLE6_SRC_LIST}) add_executable(example6 ${EXAMPLE6_SRC_LIST})
target_link_libraries(example6 miniz) target_link_libraries(example6 miniz)
if(${UNIX})
target_link_libraries(example6 m)
endif()
# add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST}) # add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST})
# target_link_libraries(miniz_tester miniz) # target_link_libraries(miniz_tester miniz)

View File

@@ -19,8 +19,8 @@ cat miniz_zip.h >> $OUTPUT_PREFIX.h
sed -i 's/#include "miniz.h"/#include "miniz.h"/' $OUTPUT_PREFIX.c sed -i 's/#include "miniz.h"/#include "miniz.h"/' $OUTPUT_PREFIX.c
for i in miniz miniz_common miniz_tdef miniz_tinfl miniz_zip for i in miniz miniz_common miniz_tdef miniz_tinfl miniz_zip
do do
sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.h sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.h
sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.c sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.c
done done
@@ -34,3 +34,5 @@ cd amalgamation
echo -e "miniz.c\nminiz.h" | zip -@ miniz echo -e "miniz.c\nminiz.h" | zip -@ miniz
echo "Amalgamation created." echo "Amalgamation created."

View File

@@ -195,6 +195,7 @@ enum
MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS = 22, MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS = 22,
MZ_ZIP_LDH_FILENAME_LEN_OFS = 26, MZ_ZIP_LDH_FILENAME_LEN_OFS = 26,
MZ_ZIP_LDH_EXTRA_LEN_OFS = 28, MZ_ZIP_LDH_EXTRA_LEN_OFS = 28,
MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR = 1<<3,
// End of central directory offsets // End of central directory offsets
MZ_ZIP_ECDH_SIG_OFS = 0, MZ_ZIP_ECDH_SIG_OFS = 0,
@@ -228,7 +229,8 @@ enum
MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED = 1, MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED = 1,
MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG = 32, MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG = 32,
MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION = 64, MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION = 64,
MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_LOCAL_DIR_IS_MASKED = 8192 MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_LOCAL_DIR_IS_MASKED = 8192,
MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 = 1<<11
}; };
typedef struct typedef struct
@@ -473,7 +475,7 @@ static MZ_FORCEINLINE mz_bool mz_zip_reader_filename_less(const mz_zip_array *pC
} \ } \
MZ_MACRO_END MZ_MACRO_END
// Heap sort of lowercased filenames, used to help accelerate plain central directory searches by mz_zip_locate_file(). (Could also use qsort(), but it could allocate memory.) // Heap sort of lowercased filenames, used to help accelerate plain central directory searches by mz_zip_reader_locate_file(). (Could also use qsort(), but it could allocate memory.)
static void mz_zip_reader_sort_central_dir_offsets_by_filename(mz_zip_archive *pZip) static void mz_zip_reader_sort_central_dir_offsets_by_filename(mz_zip_archive *pZip)
{ {
mz_zip_internal_state *pState = pZip->m_pState; mz_zip_internal_state *pState = pZip->m_pState;
@@ -925,7 +927,12 @@ static size_t mz_zip_file_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBu
return MZ_FREAD(pBuf, 1, n, pZip->m_pState->m_pFile); return MZ_FREAD(pBuf, 1, n, pZip->m_pState->m_pFile);
} }
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size) mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags)
{
return mz_zip_reader_init_file_v2(pZip, pFilename, flags, 0, 0);
}
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size)
{ {
if ((!pZip) || (!pFilename) || ((archive_size) && (archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE))) if ((!pZip) || (!pFilename) || ((archive_size) && (archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)))
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
@@ -1023,7 +1030,7 @@ static MZ_FORCEINLINE const mz_uint8 *mz_zip_get_cdh(mz_zip_archive *pZip, mz_ui
return &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index)); return &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index));
} }
mz_bool mz_zip_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index) mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index)
{ {
mz_uint m_bit_flag; mz_uint m_bit_flag;
const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
@@ -1037,7 +1044,7 @@ mz_bool mz_zip_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index)
return (m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION)) != 0; return (m_bit_flag & (MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED | MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION)) != 0;
} }
mz_bool mz_zip_is_file_supported(mz_zip_archive *pZip, mz_uint file_index) mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index)
{ {
mz_uint bit_flag; mz_uint bit_flag;
mz_uint method; mz_uint method;
@@ -1073,7 +1080,7 @@ mz_bool mz_zip_is_file_supported(mz_zip_archive *pZip, mz_uint file_index)
return MZ_TRUE; return MZ_TRUE;
} }
mz_bool mz_zip_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index) mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index)
{ {
mz_uint filename_len, attribute_mapping_id, external_attr; mz_uint filename_len, attribute_mapping_id, external_attr;
const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
@@ -1146,9 +1153,9 @@ static mz_bool mz_zip_file_stat_internal(mz_zip_archive *pZip, mz_uint file_inde
pStat->m_comment[n] = '\0'; pStat->m_comment[n] = '\0';
// Set some flags for convienance // Set some flags for convienance
pStat->m_is_directory = mz_zip_is_file_a_directory(pZip, file_index); pStat->m_is_directory = mz_zip_reader_is_file_a_directory(pZip, file_index);
pStat->m_is_encrypted = mz_zip_is_file_encrypted(pZip, file_index); pStat->m_is_encrypted = mz_zip_reader_is_file_encrypted(pZip, file_index);
pStat->m_is_supported = mz_zip_is_file_supported(pZip, file_index); pStat->m_is_supported = mz_zip_reader_is_file_supported(pZip, file_index);
// See if we need to read any zip64 extended information fields. // See if we need to read any zip64 extended information fields.
// Confusingly, these zip64 fields can be present even on non-zip64 archives (Debian zip on a huge files from stdin piped to stdout creates them). // Confusingly, these zip64 fields can be present even on non-zip64 archives (Debian zip on a huge files from stdin piped to stdout creates them).
@@ -1290,7 +1297,16 @@ static mz_bool mz_zip_locate_file_binary_search(mz_zip_archive *pZip, const char
return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND); return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
} }
mz_bool mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex) int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags)
{
mz_uint32 index;
if(!mz_zip_reader_locate_file_v2(pZip, pName, pComment, flags, &index))
return -1;
else
return (int)index;
}
mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex)
{ {
mz_uint file_index; mz_uint file_index;
size_t name_len, comment_len; size_t name_len, comment_len;
@@ -1346,7 +1362,8 @@ mz_bool mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *
} }
if ((filename_len == name_len) && (mz_zip_string_equal(pName, pFilename, filename_len, flags))) if ((filename_len == name_len) && (mz_zip_string_equal(pName, pFilename, filename_len, flags)))
{ {
*pIndex = file_index; if (pIndex)
*pIndex = file_index;
return MZ_TRUE; return MZ_TRUE;
} }
} }
@@ -1354,7 +1371,7 @@ mz_bool mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *
return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND); return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
} }
mz_bool mz_zip_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size) mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size)
{ {
int status = TINFL_STATUS_DONE; int status = TINFL_STATUS_DONE;
mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail; mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
@@ -1367,7 +1384,7 @@ mz_bool mz_zip_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index,
if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead)) if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead))
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
if (!mz_zip_file_stat(pZip, file_index, &file_stat)) if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
return MZ_FALSE; return MZ_FALSE;
// A directory or zero length file // A directory or zero length file
@@ -1497,25 +1514,25 @@ mz_bool mz_zip_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index,
return status == TINFL_STATUS_DONE; return status == TINFL_STATUS_DONE;
} }
mz_bool mz_zip_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size) mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size)
{ {
mz_uint32 file_index; mz_uint32 file_index;
if (!mz_zip_locate_file(pZip, pFilename, NULL, flags, &file_index)) if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index))
return MZ_FALSE; return MZ_FALSE;
return mz_zip_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size); return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size);
} }
mz_bool mz_zip_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags) mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags)
{ {
return mz_zip_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, NULL, 0); return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, NULL, 0);
} }
mz_bool mz_zip_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags) mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags)
{ {
return mz_zip_extract_file_to_mem_no_alloc(pZip, pFilename, pBuf, buf_size, flags, NULL, 0); return mz_zip_reader_extract_file_to_mem_no_alloc(pZip, pFilename, pBuf, buf_size, flags, NULL, 0);
} }
void *mz_zip_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags) void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags)
{ {
mz_uint64 comp_size, uncomp_size, alloc_size; mz_uint64 comp_size, uncomp_size, alloc_size;
const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
@@ -1546,7 +1563,7 @@ void *mz_zip_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *p
return NULL; return NULL;
} }
if (!mz_zip_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size, flags)) if (!mz_zip_reader_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size, flags))
{ {
pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
return NULL; return NULL;
@@ -1557,19 +1574,19 @@ void *mz_zip_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *p
return pBuf; return pBuf;
} }
void *mz_zip_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags) void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags)
{ {
mz_uint32 file_index; mz_uint32 file_index;
if (!mz_zip_locate_file(pZip, pFilename, NULL, flags, &file_index)) if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index))
{ {
if (pSize) if (pSize)
*pSize = 0; *pSize = 0;
return MZ_FALSE; return MZ_FALSE;
} }
return mz_zip_extract_to_heap(pZip, file_index, pSize, flags); return mz_zip_reader_extract_to_heap(pZip, file_index, pSize, flags);
} }
mz_bool mz_zip_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags) mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags)
{ {
int status = TINFL_STATUS_DONE; int status = TINFL_STATUS_DONE;
mz_uint file_crc32 = MZ_CRC32_INIT; mz_uint file_crc32 = MZ_CRC32_INIT;
@@ -1583,7 +1600,7 @@ mz_bool mz_zip_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_
if ((!pZip) || (!pZip->m_pState) || (!pCallback) || (!pZip->m_pRead)) if ((!pZip) || (!pZip->m_pState) || (!pCallback) || (!pZip->m_pRead))
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
if (!mz_zip_file_stat(pZip, file_index, &file_stat)) if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
return MZ_FALSE; return MZ_FALSE;
// A directory or zero length file // A directory or zero length file
@@ -1767,13 +1784,13 @@ mz_bool mz_zip_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_
return status == TINFL_STATUS_DONE; return status == TINFL_STATUS_DONE;
} }
mz_bool mz_zip_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags) mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags)
{ {
mz_uint32 file_index; mz_uint32 file_index;
if (!mz_zip_locate_file(pZip, pFilename, NULL, flags, &file_index)) if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index))
return MZ_FALSE; return MZ_FALSE;
return mz_zip_extract_to_callback(pZip, file_index, pCallback, pOpaque, flags); return mz_zip_reader_extract_to_callback(pZip, file_index, pCallback, pOpaque, flags);
} }
#ifndef MINIZ_NO_STDIO #ifndef MINIZ_NO_STDIO
@@ -1784,13 +1801,13 @@ static size_t mz_zip_file_write_callback(void *pOpaque, mz_uint64 ofs, const voi
return MZ_FWRITE(pBuf, 1, n, (MZ_FILE *)pOpaque); return MZ_FWRITE(pBuf, 1, n, (MZ_FILE *)pOpaque);
} }
mz_bool mz_zip_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags) mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags)
{ {
mz_bool status; mz_bool status;
mz_zip_archive_file_stat file_stat; mz_zip_archive_file_stat file_stat;
MZ_FILE *pFile; MZ_FILE *pFile;
if (!mz_zip_file_stat(pZip, file_index, &file_stat)) if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
return MZ_FALSE; return MZ_FALSE;
if ((file_stat.m_is_directory) || (!file_stat.m_is_supported)) if ((file_stat.m_is_directory) || (!file_stat.m_is_supported))
@@ -1800,7 +1817,7 @@ mz_bool mz_zip_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const c
if (!pFile) if (!pFile)
return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED); return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
status = mz_zip_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags); status = mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags);
if (MZ_FCLOSE(pFile) == EOF) if (MZ_FCLOSE(pFile) == EOF)
{ {
@@ -1818,35 +1835,35 @@ mz_bool mz_zip_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const c
return status; return status;
} }
mz_bool mz_zip_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags) mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags)
{ {
mz_uint32 file_index; mz_uint32 file_index;
if (!mz_zip_locate_file(pZip, pArchive_filename, NULL, flags, &file_index)) if (!mz_zip_reader_locate_file_v2(pZip, pArchive_filename, NULL, flags, &file_index))
return MZ_FALSE; return MZ_FALSE;
return mz_zip_extract_to_file(pZip, file_index, pDst_filename, flags); return mz_zip_reader_extract_to_file(pZip, file_index, pDst_filename, flags);
} }
mz_bool mz_zip_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *pFile, mz_uint flags) mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *pFile, mz_uint flags)
{ {
mz_zip_archive_file_stat file_stat; mz_zip_archive_file_stat file_stat;
if (!mz_zip_file_stat(pZip, file_index, &file_stat)) if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
return MZ_FALSE; return MZ_FALSE;
if ((file_stat.m_is_directory) || (!file_stat.m_is_supported)) if ((file_stat.m_is_directory) || (!file_stat.m_is_supported))
return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE); return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE);
return mz_zip_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags); return mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags);
} }
mz_bool mz_zip_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags) mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags)
{ {
mz_uint32 file_index; mz_uint32 file_index;
if (!mz_zip_locate_file(pZip, pArchive_filename, NULL, flags, &file_index)) if (!mz_zip_reader_locate_file_v2(pZip, pArchive_filename, NULL, flags, &file_index))
return MZ_FALSE; return MZ_FALSE;
return mz_zip_extract_to_cfile(pZip, file_index, pFile, flags); return mz_zip_reader_extract_to_cfile(pZip, file_index, pFile, flags);
} }
#endif // #ifndef MINIZ_NO_STDIO #endif // #ifndef MINIZ_NO_STDIO
@@ -2043,7 +2060,7 @@ mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint f
if ((flags & MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY) == 0) if ((flags & MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY) == 0)
{ {
if (!mz_zip_extract_to_callback(pZip, file_index, mz_zip_compute_crc32_callback, &uncomp_crc32, 0)) if (!mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_compute_crc32_callback, &uncomp_crc32, 0))
return MZ_FALSE; return MZ_FALSE;
// 1 more check to be sure, although the extract checks too. // 1 more check to be sure, although the extract checks too.
@@ -2094,10 +2111,10 @@ mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags)
mz_uint32 found_index; mz_uint32 found_index;
mz_zip_archive_file_stat stat; mz_zip_archive_file_stat stat;
if (!mz_zip_file_stat(pZip, i, &stat)) if (!mz_zip_reader_file_stat(pZip, i, &stat))
return MZ_FALSE; return MZ_FALSE;
if (!mz_zip_locate_file(pZip, stat.m_filename, NULL, 0, &found_index)) if (!mz_zip_reader_locate_file_v2(pZip, stat.m_filename, NULL, 0, &found_index))
return MZ_FALSE; return MZ_FALSE;
// This check can fail if there are duplicate filenames in the archive (which we don't check for when writing - that's up to the user) // This check can fail if there are duplicate filenames in the archive (which we don't check for when writing - that's up to the user)
@@ -2169,7 +2186,7 @@ mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zi
mz_zip_zero_struct(&zip); mz_zip_zero_struct(&zip);
if (!mz_zip_reader_init_file(&zip, pFilename, flags, 0, 0)) if (!mz_zip_reader_init_file_v2(&zip, pFilename, flags, 0, 0))
{ {
if (pErr) if (pErr)
*pErr = zip.m_last_error; *pErr = zip.m_last_error;
@@ -2399,7 +2416,12 @@ static size_t mz_zip_file_write_func(void *pOpaque, mz_uint64 file_ofs, const vo
return MZ_FWRITE(pBuf, 1, n, pZip->m_pState->m_pFile); return MZ_FWRITE(pBuf, 1, n, pZip->m_pState->m_pFile);
} }
mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags) mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning)
{
return mz_zip_writer_init_file_v2(pZip, pFilename, size_to_reserve_at_beginning, 0);
}
mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags)
{ {
MZ_FILE *pFile; MZ_FILE *pFile;
@@ -2551,9 +2573,9 @@ mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilena
} }
// TODO: pArchive_name is a terrible name here! // TODO: pArchive_name is a terrible name here!
mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags, time_t* last_modified) mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags)
{ {
return mz_zip_writer_add_mem_ex(pZip, pArchive_name, pBuf, buf_size, NULL, 0, level_and_flags, 0, 0, 0, last_modified, NULL, 0, NULL, 0); return mz_zip_writer_add_mem_ex(pZip, pArchive_name, pBuf, buf_size, NULL, 0, level_and_flags, 0, 0);
} }
typedef struct typedef struct
@@ -2737,8 +2759,14 @@ static mz_bool mz_zip_writer_write_zeros(mz_zip_archive *pZip, mz_uint64 cur_fil
return MZ_TRUE; return MZ_TRUE;
} }
mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, mz_uint16 bit_flags, time_t* last_modified, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32)
{
return mz_zip_writer_add_mem_ex_v2(pZip, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, uncomp_size, uncomp_crc32, NULL, NULL, 0, NULL, 0);
}
mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size,
mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified,
const char* user_extra_data, mz_uint user_extra_data_len, const char* user_extra_data_central, mz_uint user_extra_data_central_len) const char* user_extra_data, mz_uint user_extra_data_len, const char* user_extra_data_central, mz_uint user_extra_data_central_len)
{ {
mz_uint16 method = 0, dos_time = 0, dos_date = 0; mz_uint16 method = 0, dos_time = 0, dos_date = 0;
@@ -2752,6 +2780,10 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name
mz_uint8 *pExtra_data = NULL; mz_uint8 *pExtra_data = NULL;
mz_uint32 extra_size = 0; mz_uint32 extra_size = 0;
mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE]; mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE];
mz_uint16 bit_flags = MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
if (level_and_flags & MZ_ZIP_FLAG_UTF8_FILENAME )
bit_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8;
if ((int)level_and_flags < 0) if ((int)level_and_flags < 0)
level_and_flags = MZ_DEFAULT_LEVEL; level_and_flags = MZ_DEFAULT_LEVEL;
@@ -2858,7 +2890,7 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name
MZ_CLEAR_OBJ(local_dir_header); MZ_CLEAR_OBJ(local_dir_header);
if (uncomp_size && level) if (!store_data_uncompressed || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
{ {
method = MZ_DEFLATED; method = MZ_DEFLATED;
} }
@@ -2944,9 +2976,6 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name
cur_archive_file_ofs += buf_size; cur_archive_file_ofs += buf_size;
comp_size = buf_size; comp_size = buf_size;
if (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)
method = MZ_DEFLATED;
} }
else if (buf_size) else if (buf_size)
{ {
@@ -2972,7 +3001,7 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name
if (uncomp_size) if (uncomp_size)
{ {
MZ_ASSERT(bit_flags & (1 << 3)); MZ_ASSERT(bit_flags & MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR);
mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64]; mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64];
mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32; mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32;
@@ -3021,7 +3050,7 @@ mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
const char* user_extra_data, mz_uint user_extra_data_len, const char* user_extra_data_central, mz_uint user_extra_data_central_len) const char* user_extra_data, mz_uint user_extra_data_len, const char* user_extra_data_central, mz_uint user_extra_data_central_len)
{ {
mz_uint16 gen_flags = 1 << 3 | 1 << 11; mz_uint16 gen_flags = MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes; mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes;
mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0; mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0;
mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = size_to_add, comp_size = 0; mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = size_to_add, comp_size = 0;
@@ -3032,6 +3061,9 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE]; mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE];
mz_zip_internal_state *pState; mz_zip_internal_state *pState;
if(level_and_flags & MZ_ZIP_FLAG_UTF8_FILENAME)
gen_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8;
if ((int)level_and_flags < 0) if ((int)level_and_flags < 0)
level_and_flags = MZ_DEFAULT_LEVEL; level_and_flags = MZ_DEFAULT_LEVEL;
level = level_and_flags & 0xF; level = level_and_flags & 0xF;
@@ -3307,22 +3339,19 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
return MZ_TRUE; return MZ_TRUE;
} }
mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, MZ_TIME_T *pFile_time) mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags)
{ {
MZ_FILE *pSrc_file = NULL; MZ_FILE *pSrc_file = NULL;
mz_uint64 uncomp_size = 0; mz_uint64 uncomp_size = 0;
MZ_TIME_T file_modified_time; MZ_TIME_T file_modified_time;
MZ_TIME_T *pFile_time = NULL;
memset(&file_modified_time, 0, sizeof(file_modified_time)); memset(&file_modified_time, 0, sizeof(file_modified_time));
#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO) #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO)
if (pFile_time == NULL) pFile_time = &file_modified_time;
{ if (!mz_zip_get_file_modified_time(pSrc_filename, &file_modified_time))
pFile_time = &file_modified_time; return mz_zip_set_error(pZip, MZ_ZIP_FILE_STAT_FAILED);
if (!mz_zip_get_file_modified_time(pSrc_filename, &file_modified_time))
return mz_zip_set_error(pZip, MZ_ZIP_FILE_STAT_FAILED);
}
#endif #endif
pSrc_file = MZ_FOPEN(pSrc_filename, "rb"); pSrc_file = MZ_FOPEN(pSrc_filename, "rb");
@@ -3421,7 +3450,7 @@ static mz_bool mz_zip_writer_update_zip64_extension_block(mz_zip_array *pNew_ext
} }
// TODO: This func is now pretty freakin complex due to zip64, split it up? // TODO: This func is now pretty freakin complex due to zip64, split it up?
mz_bool mz_zip_writer_add_from_other_zip(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index) mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index)
{ {
mz_uint n, bit_flags, num_alignment_padding_bytes, src_central_dir_following_data_size; mz_uint n, bit_flags, num_alignment_padding_bytes, src_central_dir_following_data_size;
mz_uint64 src_archive_bytes_remaining, local_dir_header_ofs; mz_uint64 src_archive_bytes_remaining, local_dir_header_ofs;
@@ -3900,7 +3929,12 @@ mz_bool mz_zip_writer_end(mz_zip_archive *pZip)
} }
#ifndef MINIZ_NO_STDIO #ifndef MINIZ_NO_STDIO
mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr) mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags)
{
return mz_zip_add_mem_to_archive_file_in_place_v2(pZip_filename, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, NULL);
}
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr)
{ {
mz_bool status, created_new_archive = MZ_FALSE; mz_bool status, created_new_archive = MZ_FALSE;
mz_zip_archive zip_archive; mz_zip_archive zip_archive;
@@ -3930,7 +3964,7 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const
if (MZ_FILE_STAT(pZip_filename, &file_stat) != 0) if (MZ_FILE_STAT(pZip_filename, &file_stat) != 0)
{ {
// Create a new archive. // Create a new archive.
if (!mz_zip_writer_init_file(&zip_archive, pZip_filename, 0, level_and_flags)) if (!mz_zip_writer_init_file_v2(&zip_archive, pZip_filename, 0, level_and_flags))
{ {
if (pErr) if (pErr)
*pErr = zip_archive.m_last_error; *pErr = zip_archive.m_last_error;
@@ -3942,7 +3976,7 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const
else else
{ {
// Append to an existing archive. // Append to an existing archive.
if (!mz_zip_reader_init_file(&zip_archive, pZip_filename, level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0)) if (!mz_zip_reader_init_file_v2(&zip_archive, pZip_filename, level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0))
{ {
if (pErr) if (pErr)
*pErr = zip_archive.m_last_error; *pErr = zip_archive.m_last_error;
@@ -3960,7 +3994,7 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const
} }
} }
status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0, 0, 0, NULL, 0, NULL, 0); status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0);
actual_err = zip_archive.m_last_error; actual_err = zip_archive.m_last_error;
// Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.) // Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.)
@@ -4011,7 +4045,7 @@ void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char
} }
mz_zip_zero_struct(&zip_archive); mz_zip_zero_struct(&zip_archive);
if (!mz_zip_reader_init_file(&zip_archive, pZip_filename, flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0)) if (!mz_zip_reader_init_file_v2(&zip_archive, pZip_filename, flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0))
{ {
if (pErr) if (pErr)
*pErr = zip_archive.m_last_error; *pErr = zip_archive.m_last_error;
@@ -4019,9 +4053,9 @@ void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char
return NULL; return NULL;
} }
if (mz_zip_locate_file(&zip_archive, pArchive_name, pComment, flags, &file_index)) if (mz_zip_reader_locate_file_v2(&zip_archive, pArchive_name, pComment, flags, &file_index))
{ {
p = mz_zip_extract_to_heap(&zip_archive, file_index, pSize, flags); p = mz_zip_reader_extract_to_heap(&zip_archive, file_index, pSize, flags);
} }
mz_zip_reader_end_internal(&zip_archive, p != NULL); mz_zip_reader_end_internal(&zip_archive, p != NULL);
@@ -4179,7 +4213,7 @@ size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip)
return pZip->m_pState->m_central_dir.m_size; return pZip->m_pState->m_central_dir.m_size;
} }
mz_uint mz_zip_get_num_files(mz_zip_archive *pZip) mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip)
{ {
return pZip ? pZip->m_total_files : 0; return pZip ? pZip->m_total_files : 0;
} }
@@ -4213,7 +4247,7 @@ size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *
return pZip->m_pRead(pZip->m_pIO_opaque, file_ofs, pBuf, n); return pZip->m_pRead(pZip->m_pIO_opaque, file_ofs, pBuf, n);
} }
mz_uint mz_zip_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size) mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size)
{ {
mz_uint n; mz_uint n;
const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
@@ -4234,7 +4268,7 @@ mz_uint mz_zip_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFil
return n + 1; return n + 1;
} }
mz_bool mz_zip_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat) mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat)
{ {
return mz_zip_file_stat_internal(pZip, file_index, mz_zip_get_cdh(pZip, file_index), pStat, NULL); return mz_zip_file_stat_internal(pZip, file_index, mz_zip_get_cdh(pZip, file_index), pStat, NULL);
} }

View File

@@ -95,7 +95,8 @@ typedef enum
MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, // if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing) MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, // if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing)
MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, // validate the local headers, but don't decompress the entire file and check the crc32 MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, // validate the local headers, but don't decompress the entire file and check the crc32
MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, // use the zip64 file format, instead of the original zip file format MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, // use the zip64 file format, instead of the original zip file format
MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000 MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000,
MZ_ZIP_FLAG_UTF8_FILENAME = 0x10000
} mz_zip_flags; } mz_zip_flags;
typedef enum typedef enum
@@ -185,7 +186,8 @@ mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t si
// Read a archive from a disk file. // Read a archive from a disk file.
// file_start_ofs is the file offset where the archive actually begins, or 0. // file_start_ofs is the file offset where the archive actually begins, or 0.
// actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. // actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive.
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size); mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size);
// Read an archive from an already opened FILE, beginning at the current file position. // Read an archive from an already opened FILE, beginning at the current file position.
// The archive is assumed to be archive_size bytes long. If archive_size is < 0, then the entire rest of the file is assumed to contain the archive. // The archive is assumed to be archive_size bytes long. If archive_size is < 0, then the entire rest of the file is assumed to contain the archive.
@@ -206,7 +208,7 @@ mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip);
mz_zip_type mz_zip_get_type(mz_zip_archive *pZip); mz_zip_type mz_zip_get_type(mz_zip_archive *pZip);
// Returns the total number of files in the archive. // Returns the total number of files in the archive.
mz_uint mz_zip_get_num_files(mz_zip_archive *pZip); mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip); mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip);
mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip); mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip);
@@ -217,8 +219,10 @@ size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *
// Attempts to locates a file in the archive's central directory. // Attempts to locates a file in the archive's central directory.
// Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH // Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
// Returns -1 if the file cannot be found.
int mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
// Returns MZ_FALSE if the file cannot be found. // Returns MZ_FALSE if the file cannot be found.
mz_bool mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex); mz_bool mz_zip_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex);
// All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field. // All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field.
// Note that the m_last_error functionality is not thread safe. // Note that the m_last_error functionality is not thread safe.
@@ -229,20 +233,26 @@ mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip);
const char *mz_zip_get_error_string(mz_zip_error mz_err); const char *mz_zip_get_error_string(mz_zip_error mz_err);
// MZ_TRUE if the archive file entry is a directory entry. // MZ_TRUE if the archive file entry is a directory entry.
mz_bool mz_zip_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index); mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
// MZ_TRUE if the file is encrypted/strong encrypted. // MZ_TRUE if the file is encrypted/strong encrypted.
mz_bool mz_zip_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index); mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
// MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file. // MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file.
mz_bool mz_zip_is_file_supported(mz_zip_archive *pZip, mz_uint file_index); mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index);
// Retrieves the filename of an archive file entry. // Retrieves the filename of an archive file entry.
// Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename. // Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename.
mz_uint mz_zip_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size); mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
// Attempts to locates a file in the archive's central directory.
// Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
// Returns -1 if the file cannot be found.
int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
int mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index);
// Returns detailed information about an archive file entry. // Returns detailed information about an archive file entry.
mz_bool mz_zip_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat); mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
// MZ_TRUE if the file is in zip64 format. // MZ_TRUE if the file is in zip64 format.
// A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory. // A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory.
@@ -254,32 +264,32 @@ size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip);
// Extracts a archive file to a memory buffer using no memory allocation. // Extracts a archive file to a memory buffer using no memory allocation.
// There must be at least enough room on the stack to store the inflator's state (~34KB or so). // There must be at least enough room on the stack to store the inflator's state (~34KB or so).
mz_bool mz_zip_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
mz_bool mz_zip_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
// Extracts a archive file to a memory buffer. // Extracts a archive file to a memory buffer.
mz_bool mz_zip_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags); mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
mz_bool mz_zip_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags); mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
// Extracts a archive file to a dynamically allocated heap buffer. // Extracts a archive file to a dynamically allocated heap buffer.
// The memory will be allocated via the mz_zip_archive's alloc/realloc functions. // The memory will be allocated via the mz_zip_archive's alloc/realloc functions.
// Returns NULL and sets the last error on failure. // Returns NULL and sets the last error on failure.
void *mz_zip_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags); void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
void *mz_zip_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags); void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
// Extracts a archive file using a callback function to output the file's data. // Extracts a archive file using a callback function to output the file's data.
mz_bool mz_zip_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
mz_bool mz_zip_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
#ifndef MINIZ_NO_STDIO #ifndef MINIZ_NO_STDIO
// Extracts a archive file to a disk file and sets its last accessed and modified times. // Extracts a archive file to a disk file and sets its last accessed and modified times.
// This function only extracts files, not archive directory records. // This function only extracts files, not archive directory records.
mz_bool mz_zip_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags); mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
mz_bool mz_zip_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags); mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
// Extracts a archive file starting at the current position in the destination FILE stream. // Extracts a archive file starting at the current position in the destination FILE stream.
mz_bool mz_zip_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags); mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags);
mz_bool mz_zip_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags); mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags);
#endif #endif
#if 0 #if 0
@@ -316,7 +326,8 @@ mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uin
mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags); mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags);
#ifndef MINIZ_NO_STDIO #ifndef MINIZ_NO_STDIO
mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags); mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags);
mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags); mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags);
#endif #endif
@@ -331,18 +342,24 @@ mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilena
// Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. // Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
// To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. // To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer.
// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags, time_t* last_modified); mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
// Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data. // Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data.
// uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. // uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified.
mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, mz_uint16 bit_flags, time_t* last_modified, const char* user_extra_data_local, mz_uint user_extra_data_local_len, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char* user_extra_data_local, mz_uint user_extra_data_local_len,
const char* user_extra_data_central, mz_uint user_extra_data_central_len); const char* user_extra_data_central, mz_uint user_extra_data_central_len);
#ifndef MINIZ_NO_STDIO #ifndef MINIZ_NO_STDIO
// Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. // Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, MZ_TIME_T *pFile_time); mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
// Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. // Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream.
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add,
@@ -352,7 +369,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name,
// Adds a file to an archive by fully cloning the data from another archive. // Adds a file to an archive by fully cloning the data from another archive.
// This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data. // This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data.
mz_bool mz_zip_writer_add_from_other_zip(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index); mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index);
// Finalizes the archive by writing the central directory records followed by the end of central directory record. // Finalizes the archive by writing the central directory records followed by the end of central directory record.
// After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). // After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
@@ -373,7 +390,8 @@ mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
// Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory). // Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory).
// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
// TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. // TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong.
mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr); mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr);
// Reads a single file from an archive into a heap block. // Reads a single file from an archive into a heap block.
// If pComment is not NULL, only the file with the specified comment will be extracted. // If pComment is not NULL, only the file with the specified comment will be extracted.

31
test.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
set -e
. amalgamate.sh
g++ tests/miniz_tester.cpp tests/timer.cpp amalgamation/miniz.c -o miniz_tester -I. -ggdb -O2
for i in 1 2 3 4 5 6
do
gcc examples/example$i.c amalgamation/miniz.c -o example$i -lm -I. -ggdb
done
mkdir -p test_scratch
if ! test -e "test_scratch/linux-4.8.11"
then
cd test_scratch
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.8.11.tar.xz -O linux-4.8.11.tar.xz
tar xf linux-4.8.11.tar.xz
cd ..
fi
cd test_scratch
../miniz_tester -v a linux-4.8.11
../miniz_tester -v -r a linux-4.8.11
../miniz_tester -v -b -r a linux-4.8.11
../miniz_tester -v -a a linux-4.8.11
mkdir large_file
truncate -s 5G large_file/lf
../miniz_tester -v -a a large_file

View File

@@ -922,7 +922,7 @@ static bool zip_create(const char *pZip_filename, const char *pSrc_filename)
return true; return true;
} }
static size_t zip_write_callback(void *pOpaque, uint64 ofs, const void *pBuf, size_t n) static size_t zip_write_callback(void *pOpaque, mz_uint64 ofs, const void *pBuf, size_t n)
{ {
(void)pOpaque, (void)ofs, (void)pBuf, (void)n; (void)pOpaque, (void)ofs, (void)pBuf, (void)n;
return n; return n;
@@ -957,7 +957,7 @@ static bool zip_extract(const char *pZip_filename, const char *pDst_filename)
if (!mz_zip_reader_extract_to_file(&zip, file_index, pDst_filename, 0)) if (!mz_zip_reader_extract_to_file(&zip, file_index, pDst_filename, 0))
{ {
print_error("Failed extracting test.bin from archive \"%s\"!\n", pZip_filename); print_error("Failed extracting test.bin from archive \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
mz_zip_reader_end(&zip); mz_zip_reader_end(&zip);
return false; return false;
} }
@@ -967,7 +967,7 @@ static bool zip_extract(const char *pZip_filename, const char *pDst_filename)
mz_zip_archive_file_stat stat; mz_zip_archive_file_stat stat;
if (!mz_zip_reader_file_stat(&zip, i, &stat)) if (!mz_zip_reader_file_stat(&zip, i, &stat))
{ {
print_error("Failed testing archive \"%s\"!\n", pZip_filename); print_error("Failed testing archive -1 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
mz_zip_reader_end(&zip); mz_zip_reader_end(&zip);
return false; return false;
} }
@@ -977,19 +977,22 @@ static bool zip_extract(const char *pZip_filename, const char *pDst_filename)
mz_bool status = mz_zip_reader_extract_to_callback(&zip, i, zip_write_callback, NULL, 0); mz_bool status = mz_zip_reader_extract_to_callback(&zip, i, zip_write_callback, NULL, 0);
if (!status) if (!status)
{ {
print_error("Failed testing archive \"%s\"!\n", pZip_filename); print_error("Failed testing archive -2 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
mz_zip_reader_end(&zip); mz_zip_reader_end(&zip);
return false; return false;
} }
void *p = mz_zip_reader_extract_to_heap(&zip, i, &size, 0); if (stat.m_uncomp_size<100*1024*1024)
if (!p)
{ {
print_error("Failed testing archive \"%s\"!\n", pZip_filename); void *p = mz_zip_reader_extract_to_heap(&zip, i, &size, 0);
mz_zip_reader_end(&zip); if (!p)
return false; {
print_error("Failed testing archive -3 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
mz_zip_reader_end(&zip);
return false;
}
free(p);
} }
free(p);
} }
printf("Verified %u files\n", mz_zip_reader_get_num_files(&zip)); printf("Verified %u files\n", mz_zip_reader_get_num_files(&zip));
@@ -1218,11 +1221,6 @@ static bool test_recursive(const char *pPath, comp_options options)
bool status; bool status;
if (file_options.m_archive_test) if (file_options.m_archive_test)
{ {
if (src_file_size > 0xFFF00000)
{
printf("Skipping too big file \"%s\"\n", src_file.c_str());
continue;
}
printf("Creating test archive with file \"%s\", size " QUAD_INT_FMT "\n", src_file.c_str(), src_file_size); printf("Creating test archive with file \"%s\", size " QUAD_INT_FMT "\n", src_file.c_str(), src_file_size);
status = zip_create(cmp_file, src_file.c_str()); status = zip_create(cmp_file, src_file.c_str());
} }
@@ -1309,7 +1307,7 @@ static bool test_recursive(const char *pPath, comp_options options)
return true; return true;
} }
static size_t dummy_zip_file_write_callback(void *pOpaque, uint64 ofs, const void *pBuf, size_t n) static size_t dummy_zip_file_write_callback(void *pOpaque, mz_uint64 ofs, const void *pBuf, size_t n)
{ {
(void)ofs; (void)pBuf; (void)ofs; (void)pBuf;
uint32 *pCRC = (uint32*)pOpaque; uint32 *pCRC = (uint32*)pOpaque;