From 5387227c546607421faa5754af2a062dcb51c176 Mon Sep 17 00:00:00 2001 From: Thomas Gamper Date: Thu, 31 Dec 2020 17:38:22 +0100 Subject: [PATCH 1/2] mz_zip_rw - add append argument to mz_zip_writer_open function --- mz_zip_rw.c | 14 +++++++++++--- mz_zip_rw.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mz_zip_rw.c b/mz_zip_rw.c index 8e37312e..b1e60ed5 100644 --- a/mz_zip_rw.c +++ b/mz_zip_rw.c @@ -1116,8 +1116,16 @@ static int32_t mz_zip_writer_open_int(void *handle, void *stream, int32_t mode) return MZ_OK; } -int32_t mz_zip_writer_open(void *handle, void *stream) { - return mz_zip_writer_open_int(handle, stream, MZ_OPEN_MODE_WRITE); +int32_t mz_zip_writer_open(void *handle, void *stream, uint8_t append) { + int32_t mode = MZ_OPEN_MODE_WRITE; + + if (append) { + mode |= MZ_OPEN_MODE_APPEND; + } else { + mode |= MZ_OPEN_MODE_CREATE; + } + + return mz_zip_writer_open_int(handle, stream, mode); } int32_t mz_zip_writer_open_file(void *handle, const char *path, int64_t disk_size, uint8_t append) { @@ -1213,7 +1221,7 @@ int32_t mz_zip_writer_open_file_in_memory(void *handle, const char *path) { mz_stream_os_delete(&file_stream); if (err == MZ_OK) - err = mz_zip_writer_open(handle, writer->mem_stream); + err = mz_zip_writer_open(handle, writer->mem_stream, 1); if (err != MZ_OK) mz_zip_writer_close(handle); diff --git a/mz_zip_rw.h b/mz_zip_rw.h index 10216e82..63d7f4c9 100644 --- a/mz_zip_rw.h +++ b/mz_zip_rw.h @@ -170,7 +170,7 @@ typedef int32_t (*mz_zip_writer_entry_cb)(void *handle, void *userdata, mz_zip_f int32_t mz_zip_writer_is_open(void *handle); /* Checks to see if the zip file is open */ -int32_t mz_zip_writer_open(void *handle, void *stream); +int32_t mz_zip_writer_open(void *handle, void *stream, uint8_t append); /* Opens zip file from stream */ int32_t mz_zip_writer_open_file(void *handle, const char *path, int64_t disk_size, uint8_t append); From 3c0f15312691a9263a8810dc26253d1d19353cde Mon Sep 17 00:00:00 2001 From: Thomas Gamper Date: Thu, 31 Dec 2020 17:39:48 +0100 Subject: [PATCH 2/2] mz_zip_rw.md - document new append parameter, update example --- doc/mz_zip_rw.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/mz_zip_rw.md b/doc/mz_zip_rw.md index d7f35c67..ca7d2a28 100644 --- a/doc/mz_zip_rw.md +++ b/doc/mz_zip_rw.md @@ -1331,6 +1331,7 @@ if (mz_zip_writer_is_open(zip_writer) == MZ_OK) |-|-|-| |void *|handle|_mz_zip_writer_ instance| |void *|stream|_mz_stream_ instance| +|uint8_t|append|Opens in append mode if 1| **Return** |Type|Description| @@ -1345,9 +1346,9 @@ const char *path = "c:\\my.zip"; mz_zip_writer_create(&zip_writer); mz_stream_os_create(&file_stream); -err = mz_stream_os_open(file_stream, path, MZ_OPEN_MODE_READ); +err = mz_stream_os_open(file_stream, path, MZ_OPEN_MODE_WRITE | MZ_OPEN_MODE_CREATE); if (err == MZ_OK) { - err = mz_zip_writer_open(zip_writer, file_stream); + err = mz_zip_writer_open(zip_writer, file_stream, 0); if (err == MZ_OK) { printf("Zip writer was opened %s\n", path); mz_zip_writer_close(zip_writer);