mirror of
https://github.com/QuasarApp/zip.git
synced 2025-04-28 05:14:34 +00:00
fix issue 169 (#170)
Co-authored-by: jinfeihan57 <hanjinfei57@gmail.com>
This commit is contained in:
parent
0cc4e16aca
commit
878cdc06fe
10
README.md
10
README.md
@ -161,7 +161,7 @@ char *outbuf = NULL;
|
||||
size_t outbufsize = 0;
|
||||
|
||||
const char *inbuf = "Append some data here...\0";
|
||||
struct zip_t *zip = zip_open_stream(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
||||
struct zip_t *zip = zip_stream_open(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
@ -170,9 +170,9 @@ struct zip_t *zip = zip_open_stream(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w')
|
||||
zip_entry_close(zip);
|
||||
|
||||
/* copy compressed stream into outbuf */
|
||||
zip_copy_stream(zip, (void **)&outbuf, &outbufsize);
|
||||
zip_stream_copy(zip, (void **)&outbuf, &outbufsize);
|
||||
}
|
||||
zip_close_stream(zip);
|
||||
zip_stream_close(zip);
|
||||
|
||||
free(outbuf);
|
||||
```
|
||||
@ -183,7 +183,7 @@ free(outbuf);
|
||||
char *buf = NULL;
|
||||
ssize_t bufsize = 0;
|
||||
|
||||
struct zip_t *zip = zip_open_stream(zipstream, zipstreamsize, 0, 'r');
|
||||
struct zip_t *zip = zip_stream_open(zipstream, zipstreamsize, 0, 'r');
|
||||
{
|
||||
zip_entry_open(zip, "foo-1.txt");
|
||||
{
|
||||
@ -191,7 +191,7 @@ struct zip_t *zip = zip_open_stream(zipstream, zipstreamsize, 0, 'r');
|
||||
}
|
||||
zip_entry_close(zip);
|
||||
}
|
||||
zip_close_stream(zip);
|
||||
zip_stream_close(zip);
|
||||
|
||||
free(buf);
|
||||
```
|
||||
|
@ -1043,7 +1043,7 @@ int zip_extract(const char *zipname, const char *dir,
|
||||
return status;
|
||||
}
|
||||
|
||||
int zip_extract_stream(const char *stream, size_t size, const char *dir,
|
||||
int zip_stream_extract(const char *stream, size_t size, const char *dir,
|
||||
int (*on_extract)(const char *filename, void *arg),
|
||||
void *arg) {
|
||||
mz_zip_archive zip_archive;
|
||||
@ -1078,7 +1078,7 @@ struct entry_mark {
|
||||
mz_uint64 lf_length;
|
||||
};
|
||||
|
||||
struct zip_t *zip_open_stream(const char *stream, size_t size, int level,
|
||||
struct zip_t *zip_stream_open(const char *stream, size_t size, int level,
|
||||
char mode) {
|
||||
struct zip_t *zip = NULL;
|
||||
zip = (struct zip_t *)calloc((size_t)1, sizeof(struct zip_t));
|
||||
@ -1119,7 +1119,7 @@ static inline void zip_write_end(struct zip_t *zip) {
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t zip_copy_stream(struct zip_t *zip, void **buf, ssize_t *bufsize) {
|
||||
ssize_t zip_stream_copy(struct zip_t *zip, void **buf, ssize_t *bufsize) {
|
||||
if (zip == NULL)
|
||||
return -1;
|
||||
zip_write_end(zip);
|
||||
@ -1130,7 +1130,7 @@ ssize_t zip_copy_stream(struct zip_t *zip, void **buf, ssize_t *bufsize) {
|
||||
return zip->archive.m_archive_size;
|
||||
}
|
||||
|
||||
void zip_close_stream(struct zip_t *zip) {
|
||||
void zip_stream_close(struct zip_t *zip) {
|
||||
if (zip) {
|
||||
mz_zip_writer_end(&(zip->archive));
|
||||
mz_zip_reader_end(&(zip->archive));
|
||||
|
@ -318,7 +318,7 @@ extern int zip_extract(const char *zipname, const char *dir,
|
||||
*
|
||||
* @return the return code - 0 on success, negative number (< 0) on error.
|
||||
*/
|
||||
extern int zip_extract_stream(const char *stream, size_t size, const char *dir,
|
||||
extern int zip_stream_extract(const char *stream, size_t size, const char *dir,
|
||||
int (*on_extract)(const char *filename,
|
||||
void *arg),
|
||||
void *arg);
|
||||
@ -331,7 +331,7 @@ extern int zip_extract_stream(const char *stream, size_t size, const char *dir,
|
||||
*
|
||||
* @return the zip archive handler or NULL on error
|
||||
*/
|
||||
extern struct zip_t *zip_open_stream(const char *stream, size_t size, int level,
|
||||
extern struct zip_t *zip_stream_open(const char *stream, size_t size, int level,
|
||||
char mode);
|
||||
|
||||
/**
|
||||
@ -343,7 +343,7 @@ extern struct zip_t *zip_open_stream(const char *stream, size_t size, int level,
|
||||
*
|
||||
* @return copy size
|
||||
*/
|
||||
extern ssize_t zip_copy_stream(struct zip_t *zip, void **buf, ssize_t *bufsize);
|
||||
extern ssize_t zip_stream_copy(struct zip_t *zip, void **buf, ssize_t *bufsize);
|
||||
|
||||
/**
|
||||
* Close zip archive releases resources.
|
||||
@ -352,7 +352,7 @@ extern ssize_t zip_copy_stream(struct zip_t *zip, void **buf, ssize_t *bufsize);
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
extern void zip_close_stream(struct zip_t *zip);
|
||||
extern void zip_stream_close(struct zip_t *zip);
|
||||
|
||||
/**
|
||||
* Deletes zip archive entries.
|
||||
|
14
test/test.c
14
test/test.c
@ -499,7 +499,7 @@ static void test_unix_permissions(void) {
|
||||
static void test_extract_stream(void) {
|
||||
assert(0 > zip_extract("non_existing_directory/non_existing_archive.zip", ".",
|
||||
NULL, NULL));
|
||||
assert(0 > zip_extract_stream("", 0, ".", NULL, NULL));
|
||||
assert(0 > zip_stream_extract("", 0, ".", NULL, NULL));
|
||||
|
||||
#if defined(_WIN64) || defined(_WIN32) || defined(__WIN32__)
|
||||
#else
|
||||
@ -534,7 +534,7 @@ static void test_extract_stream(void) {
|
||||
size_t size = fread(stream, sizeof(char), filesize, fp);
|
||||
assert(filesize == size);
|
||||
|
||||
assert(0 == zip_extract_stream(stream, size, ".", NULL, NULL));
|
||||
assert(0 == zip_stream_extract(stream, size, ".", NULL, NULL));
|
||||
|
||||
fclose(fp);
|
||||
remove(RFILE);
|
||||
@ -549,7 +549,7 @@ static void test_open_stream(void) {
|
||||
remove(ZIPNAME);
|
||||
/* COMPRESS MEM TO MEM */
|
||||
struct zip_t *zip =
|
||||
zip_open_stream(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
||||
zip_stream_open(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
||||
assert(zip != NULL);
|
||||
|
||||
assert(0 == zip_entry_open(zip, "test/test-1.txt"));
|
||||
@ -558,10 +558,10 @@ static void test_open_stream(void) {
|
||||
|
||||
/* write compressed mem to file */
|
||||
char *buf_encode = NULL;
|
||||
size_t n = zip_copy_stream(zip, (void **)&buf_encode, NULL);
|
||||
zip_close_stream(zip);
|
||||
size_t n = zip_stream_copy(zip, (void **)&buf_encode, NULL);
|
||||
zip_stream_close(zip);
|
||||
/* DECOMPRESS MEM TO MEM */
|
||||
struct zip_t *zipStream = zip_open_stream(buf_encode, n, 0, 'r');
|
||||
struct zip_t *zipStream = zip_stream_open(buf_encode, n, 0, 'r');
|
||||
assert(zipStream != NULL);
|
||||
|
||||
assert(0 == zip_entry_open(zipStream, "test/test-1.txt"));
|
||||
@ -571,7 +571,7 @@ static void test_open_stream(void) {
|
||||
bufsize = zip_entry_read(zipStream, (void **)&buf, NULL);
|
||||
assert(0 == strncmp(buf, TESTDATA1, (size_t)bufsize));
|
||||
assert(0 == zip_entry_close(zipStream));
|
||||
zip_close_stream(zipStream);
|
||||
zip_stream_close(zipStream);
|
||||
|
||||
free(buf);
|
||||
free(buf_encode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user