Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/zip writer stream open append #544

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/mz_zip_rw.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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);
Expand Down
14 changes: 11 additions & 3 deletions mz_zip_rw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion mz_zip_rw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down