mirror of
https://github.com/eledio-devices/thirdparty-miniz.git
synced 2025-11-01 16:14:13 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c36ab0230 | ||
|
|
4fa873b0f8 | ||
|
|
e2c4080f23 |
@@ -1530,4 +1530,3 @@ void tdefl_compressor_free(tdefl_compressor *pComp)
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* ------------------- Low-level Decompression (completely independent from all compression API's) */
|
/* ------------------- Low-level Decompression (completely independent from all compression API's) */
|
||||||
|
|
||||||
#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
|
#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
|
||||||
@@ -46,7 +45,8 @@ extern "C" {
|
|||||||
status = result; \
|
status = result; \
|
||||||
r->m_state = state_index; \
|
r->m_state = state_index; \
|
||||||
goto common_exit; \
|
goto common_exit; \
|
||||||
case state_index:; \
|
case state_index: \
|
||||||
|
; \
|
||||||
} \
|
} \
|
||||||
MZ_MACRO_END
|
MZ_MACRO_END
|
||||||
#define TINFL_CR_RETURN_FOREVER(state_index, result) \
|
#define TINFL_CR_RETURN_FOREVER(state_index, result) \
|
||||||
@@ -732,4 +732,3 @@ void tinfl_decompressor_free(tinfl_decompressor *pDecomp)
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ typedef enum
|
|||||||
/* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
|
/* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
|
||||||
/* so I may need to add some code to address this. */
|
/* so I may need to add some code to address this. */
|
||||||
TINFL_STATUS_HAS_MORE_OUTPUT = 2
|
TINFL_STATUS_HAS_MORE_OUTPUT = 2
|
||||||
|
|
||||||
} tinfl_status;
|
} tinfl_status;
|
||||||
|
|
||||||
/* Initializes the decompressor to its initial state. */
|
/* Initializes the decompressor to its initial state. */
|
||||||
|
|||||||
39
miniz_zip.c
39
miniz_zip.c
@@ -2329,7 +2329,7 @@ static mz_bool mz_zip_writer_end_internal(mz_zip_archive *pZip, mz_bool set_last
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags)
|
mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags)
|
||||||
{
|
{
|
||||||
mz_bool zip64 = (flags & MZ_ZIP_FLAG_WRITE_ZIP64) != 0;
|
mz_bool zip64 = (flags & MZ_ZIP_FLAG_WRITE_ZIP64) != 0;
|
||||||
|
|
||||||
@@ -2378,7 +2378,12 @@ mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uin
|
|||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(mz_zip_archive *pZip, mz_uint64 existing_size)
|
||||||
|
{
|
||||||
|
return mz_zip_writer_init_v2(pZip, existing_size, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags)
|
||||||
{
|
{
|
||||||
pZip->m_pWrite = mz_zip_heap_write_func;
|
pZip->m_pWrite = mz_zip_heap_write_func;
|
||||||
|
|
||||||
@@ -2387,7 +2392,7 @@ mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_
|
|||||||
|
|
||||||
pZip->m_pIO_opaque = pZip;
|
pZip->m_pIO_opaque = pZip;
|
||||||
|
|
||||||
if (!mz_zip_writer_init(pZip, size_to_reserve_at_beginning, flags))
|
if (!mz_zip_writer_init_v2(pZip, size_to_reserve_at_beginning, flags))
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
|
|
||||||
pZip->m_zip_type = MZ_ZIP_TYPE_HEAP;
|
pZip->m_zip_type = MZ_ZIP_TYPE_HEAP;
|
||||||
@@ -2405,6 +2410,11 @@ mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_
|
|||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size)
|
||||||
|
{
|
||||||
|
return mz_zip_writer_init_heap_v2(pZip, size_to_reserve_at_beginning, initial_allocation_size, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef MINIZ_NO_STDIO
|
#ifndef MINIZ_NO_STDIO
|
||||||
static size_t mz_zip_file_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
|
static size_t mz_zip_file_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
|
||||||
{
|
{
|
||||||
@@ -2438,7 +2448,7 @@ mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename,
|
|||||||
|
|
||||||
pZip->m_pIO_opaque = pZip;
|
pZip->m_pIO_opaque = pZip;
|
||||||
|
|
||||||
if (!mz_zip_writer_init(pZip, size_to_reserve_at_beginning, flags))
|
if (!mz_zip_writer_init_v2(pZip, size_to_reserve_at_beginning, flags))
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
|
|
||||||
if (NULL == (pFile = MZ_FOPEN(pFilename, (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) ? "w+b" : "wb")))
|
if (NULL == (pFile = MZ_FOPEN(pFilename, (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) ? "w+b" : "wb")))
|
||||||
@@ -2482,7 +2492,7 @@ mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint f
|
|||||||
|
|
||||||
pZip->m_pIO_opaque = pZip;
|
pZip->m_pIO_opaque = pZip;
|
||||||
|
|
||||||
if (!mz_zip_writer_init(pZip, 0, flags))
|
if (!mz_zip_writer_init_v2(pZip, 0, flags))
|
||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
|
|
||||||
pZip->m_pState->m_pFile = pFile;
|
pZip->m_pState->m_pFile = pFile;
|
||||||
@@ -2493,7 +2503,7 @@ mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint f
|
|||||||
}
|
}
|
||||||
#endif /* #ifndef MINIZ_NO_STDIO */
|
#endif /* #ifndef MINIZ_NO_STDIO */
|
||||||
|
|
||||||
mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
|
mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
|
||||||
{
|
{
|
||||||
mz_zip_internal_state *pState;
|
mz_zip_internal_state *pState;
|
||||||
|
|
||||||
@@ -2578,6 +2588,11 @@ mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilena
|
|||||||
return MZ_TRUE;
|
return MZ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename)
|
||||||
|
{
|
||||||
|
return mz_zip_writer_init_from_reader_v2(pZip, pFilename, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* 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)
|
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)
|
||||||
{
|
{
|
||||||
@@ -2788,7 +2803,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
|||||||
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 = 0;
|
mz_uint16 bit_flags = 0;
|
||||||
|
|
||||||
if(uncomp_size)
|
if (uncomp_size || (buf_size && !(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
|
||||||
bit_flags |= MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
|
bit_flags |= MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
|
||||||
|
|
||||||
if (level_and_flags & MZ_ZIP_FLAG_UTF8_FILENAME)
|
if (level_and_flags & MZ_ZIP_FLAG_UTF8_FILENAME)
|
||||||
@@ -3992,7 +4007,7 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, co
|
|||||||
return MZ_FALSE;
|
return MZ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mz_zip_writer_init_from_reader(&zip_archive, pZip_filename, level_and_flags))
|
if (!mz_zip_writer_init_from_reader_v2(&zip_archive, pZip_filename, level_and_flags))
|
||||||
{
|
{
|
||||||
if (pErr)
|
if (pErr)
|
||||||
*pErr = zip_archive.m_last_error;
|
*pErr = zip_archive.m_last_error;
|
||||||
@@ -4036,7 +4051,7 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, co
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr)
|
void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr)
|
||||||
{
|
{
|
||||||
mz_uint32 file_index;
|
mz_uint32 file_index;
|
||||||
mz_zip_archive zip_archive;
|
mz_zip_archive zip_archive;
|
||||||
@@ -4075,6 +4090,11 @@ void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags)
|
||||||
|
{
|
||||||
|
return mz_zip_extract_archive_file_to_heap_v2(pZip_filename, pArchive_name, NULL, pSize, flags, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* #ifndef MINIZ_NO_STDIO */
|
#endif /* #ifndef MINIZ_NO_STDIO */
|
||||||
|
|
||||||
#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */
|
#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */
|
||||||
@@ -4298,4 +4318,3 @@ mz_bool mz_zip_end(mz_zip_archive *pZip)
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
15
miniz_zip.h
15
miniz_zip.h
@@ -322,8 +322,10 @@ mz_bool mz_zip_end(mz_zip_archive *pZip);
|
|||||||
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
|
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
|
||||||
|
|
||||||
/* Inits a ZIP archive writer. */
|
/* Inits a ZIP archive writer. */
|
||||||
mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags);
|
mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
|
||||||
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_v2(mz_zip_archive *pZip, mz_uint64 existing_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_bool mz_zip_writer_init_heap_v2(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_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
|
||||||
@@ -337,7 +339,8 @@ mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint f
|
|||||||
/* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */
|
/* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */
|
||||||
/* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */
|
/* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */
|
||||||
/* the archive is finalized the file's central directory will be hosed. */
|
/* the archive is finalized the file's central directory will be hosed. */
|
||||||
mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename, mz_uint flags);
|
mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
|
||||||
|
mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags);
|
||||||
|
|
||||||
/* 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. */
|
||||||
@@ -353,9 +356,6 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
|||||||
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,
|
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. */
|
||||||
@@ -396,7 +396,8 @@ mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, co
|
|||||||
/* 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. */
|
||||||
/* Returns NULL on failure. */
|
/* Returns NULL on failure. */
|
||||||
void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr);
|
void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags);
|
||||||
|
void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr);
|
||||||
|
|
||||||
#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */
|
#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user