Allow retrievable of interfaces for help for compatibility layer.

This commit is contained in:
Nathan Moinvaziri 2017-10-08 21:48:28 -07:00
parent 7d9f250ed0
commit 1e3300f758
20 changed files with 329 additions and 175 deletions

104
mz_strm.c
View File

@ -28,27 +28,27 @@
int32_t mz_stream_open(void *stream, const char *path, int32_t mode)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->open == NULL)
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->open == NULL)
return MZ_STREAM_ERROR;
return strm->open(strm, path, mode);
return strm->vtbl->open(strm, path, mode);
}
int32_t mz_stream_is_open(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->is_open == NULL)
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->is_open == NULL)
return MZ_STREAM_ERROR;
return strm->is_open(strm);
return strm->vtbl->is_open(strm);
}
int32_t mz_stream_read(void *stream, void *buf, int32_t size)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->read == NULL)
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->read == NULL)
return MZ_PARAM_ERROR;
if (mz_stream_is_open(stream) != MZ_OK)
return MZ_STREAM_ERROR;
if (strm->is_open != NULL && strm->is_open(strm) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->read(strm, buf, size);
return strm->vtbl->read(strm, buf, size);
}
int32_t mz_stream_read_uint8(void *stream, uint8_t *value)
@ -134,13 +134,13 @@ int32_t mz_stream_read_uint64(void *stream, uint64_t *value)
int32_t mz_stream_write(void *stream, const void *buf, int32_t size)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->write == NULL)
return MZ_STREAM_ERROR;
if (size == 0)
return size;
if (strm->is_open != NULL && strm->is_open(strm) != MZ_OK)
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->write == NULL)
return MZ_PARAM_ERROR;
if (mz_stream_is_open(stream) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->write(strm, buf, size);
return strm->vtbl->write(strm, buf, size);
}
static int32_t mz_stream_write_value(void *stream, uint64_t value, uint32_t len)
@ -214,37 +214,39 @@ int32_t mz_stream_copy(void *target, void *source, int32_t len)
int64_t mz_stream_tell(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->tell == NULL)
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->tell == NULL)
return MZ_PARAM_ERROR;
if (mz_stream_is_open(stream) != MZ_OK)
return MZ_STREAM_ERROR;
if (strm->is_open != NULL && strm->is_open(strm) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->tell(strm);
return strm->vtbl->tell(strm);
}
int32_t mz_stream_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->seek == NULL)
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->seek == NULL)
return MZ_PARAM_ERROR;
if (mz_stream_is_open(stream) != MZ_OK)
return MZ_STREAM_ERROR;
if (strm->is_open != NULL && strm->is_open(strm) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->seek(strm, offset, origin);
return strm->vtbl->seek(strm, offset, origin);
}
int32_t mz_stream_close(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->close == NULL)
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->close == NULL)
return MZ_PARAM_ERROR;
if (mz_stream_is_open(stream) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->close(strm);
return strm->vtbl->close(strm);
}
int32_t mz_stream_error(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->error == NULL)
return MZ_STREAM_ERROR;
return strm->error(strm);
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->error == NULL)
return MZ_PARAM_ERROR;
return strm->vtbl->error(strm);
}
int32_t mz_stream_set_base(void *stream, void *base)
@ -257,17 +259,17 @@ int32_t mz_stream_set_base(void *stream, void *base)
int64_t mz_stream_get_total_in(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm->get_total_in == NULL)
return MZ_STREAM_ERROR;
return strm->get_total_in(stream);
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->get_total_in == NULL)
return MZ_PARAM_ERROR;
return strm->vtbl->get_total_in(stream);
}
int64_t mz_stream_get_total_out(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm->get_total_out == NULL)
return MZ_STREAM_ERROR;
return strm->get_total_out(stream);
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->get_total_out == NULL)
return MZ_PARAM_ERROR;
return strm->vtbl->get_total_out(stream);
}
void *mz_stream_create(void **stream)
@ -276,7 +278,9 @@ void *mz_stream_create(void **stream)
if (stream == NULL)
return NULL;
strm = (mz_stream *)*stream;
return strm->create(stream);
if (strm == NULL || strm->vtbl == NULL || strm->vtbl->create == NULL)
return NULL;
return strm->vtbl->create(stream);
}
void mz_stream_delete(void **stream)
@ -285,7 +289,8 @@ void mz_stream_delete(void **stream)
if (stream == NULL)
return;
strm = (mz_stream *)*stream;
strm->delete(stream);
if (strm != NULL && strm->vtbl != NULL && strm->vtbl->delete != NULL)
strm->vtbl->delete(stream);
*stream = NULL;
}
@ -363,6 +368,25 @@ int64_t mz_stream_passthru_get_total_out(void *stream)
return passthru->total_out;
}
/***************************************************************************/
mz_stream_vtbl mz_stream_passthru_vtbl = {
mz_stream_passthru_open,
mz_stream_passthru_is_open,
mz_stream_passthru_read,
mz_stream_passthru_write,
mz_stream_passthru_tell,
mz_stream_passthru_seek,
mz_stream_passthru_close,
mz_stream_passthru_error,
mz_stream_passthru_create,
mz_stream_passthru_delete,
mz_stream_passthru_get_total_in,
mz_stream_passthru_get_total_out
};
/***************************************************************************/
void *mz_stream_passthru_create(void **stream)
{
mz_stream_passthru *passthru = NULL;
@ -371,19 +395,7 @@ void *mz_stream_passthru_create(void **stream)
if (passthru != NULL)
{
memset(passthru, 0, sizeof(mz_stream_passthru));
passthru->stream.open = mz_stream_passthru_open;
passthru->stream.is_open = mz_stream_passthru_is_open;
passthru->stream.read = mz_stream_passthru_read;
passthru->stream.write = mz_stream_passthru_write;
passthru->stream.tell = mz_stream_passthru_tell;
passthru->stream.seek = mz_stream_passthru_seek;
passthru->stream.close = mz_stream_passthru_close;
passthru->stream.error = mz_stream_passthru_error;
passthru->stream.create = mz_stream_passthru_create;
passthru->stream.delete = mz_stream_passthru_delete;
passthru->stream.get_total_in = mz_stream_passthru_get_total_in;
passthru->stream.get_total_out = mz_stream_passthru_get_total_out;
passthru->stream.vtbl = &mz_stream_passthru_vtbl;
}
if (stream != NULL)
*stream = passthru;

View File

@ -36,6 +36,10 @@ extern "C" {
#define MZ_STREAM_MODE_CREATE (0x08)
#define MZ_STREAM_MODE_EXISTING (0x10)
#define MZ_STREAM_PROPERTY_TOTAL_IN (1)
#define MZ_STREAM_PROPERTY_TOTAL_OUT (2)
#define MZ_STREAM_PROPERTY_DISK_SIZE (3)
/***************************************************************************/
typedef int32_t (*mz_stream_open_cb) (void *stream, const char *path, int32_t mode);
@ -46,16 +50,25 @@ typedef int64_t (*mz_stream_tell_cb) (void *stream);
typedef int32_t (*mz_stream_seek_cb) (void *stream, int64_t offset, int32_t origin);
typedef int32_t (*mz_stream_close_cb) (void *stream);
typedef int32_t (*mz_stream_error_cb) (void *stream);
typedef int64_t (*mz_stream_set_property_ptr) (void *stream, int32_t property, void *value);
typedef int64_t (*mz_stream_get_property_ptr) (void *stream, int32_t property, void **value);
typedef int64_t (*mz_stream_get_property_int64)(void *stream, int32_t property, int64_t *value);
typedef void* (*mz_stream_create_cb) (void **stream);
typedef void (*mz_stream_delete_cb) (void **stream);
typedef int64_t (*mz_stream_set_base_cb) (void *stream);
typedef int64_t (*mz_stream_get_total_in_cb) (void *stream);
typedef int64_t (*mz_stream_get_total_out_cb) (void *stream);
/***************************************************************************/
typedef struct mz_stream_s
typedef struct mz_stream_vtbl_s
{
struct mz_stream_s *base;
mz_stream_open_cb open;
mz_stream_is_open_cb is_open;
mz_stream_read_cb read;
@ -68,6 +81,11 @@ typedef struct mz_stream_s
mz_stream_delete_cb delete;
mz_stream_get_total_in_cb get_total_in;
mz_stream_get_total_out_cb get_total_out;
} mz_stream_vtbl;
typedef struct mz_stream_s {
mz_stream_vtbl *vtbl;
struct mz_stream_s *base;
} mz_stream;
/***************************************************************************/

View File

@ -30,6 +30,23 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_aes_vtbl = {
mz_stream_aes_open,
mz_stream_aes_is_open,
mz_stream_aes_read,
mz_stream_aes_write,
mz_stream_aes_tell,
mz_stream_aes_seek,
mz_stream_aes_close,
mz_stream_aes_error,
mz_stream_aes_create,
mz_stream_aes_delete,
mz_stream_aes_get_total_in,
mz_stream_aes_get_total_out
};
/***************************************************************************/
typedef struct mz_stream_aes_s {
mz_stream stream;
fcrypt_ctx crypt_ctx;
@ -231,19 +248,7 @@ void *mz_stream_aes_create(void **stream)
if (aes != NULL)
{
memset(aes, 0, sizeof(mz_stream_aes));
aes->stream.open = mz_stream_aes_open;
aes->stream.is_open = mz_stream_aes_is_open;
aes->stream.read = mz_stream_aes_read;
aes->stream.write = mz_stream_aes_write;
aes->stream.tell = mz_stream_aes_tell;
aes->stream.seek = mz_stream_aes_seek;
aes->stream.close = mz_stream_aes_close;
aes->stream.error = mz_stream_aes_error;
aes->stream.create = mz_stream_aes_create;
aes->stream.delete = mz_stream_aes_delete;
aes->stream.get_total_in = mz_stream_aes_get_total_in;
aes->stream.get_total_out = mz_stream_aes_get_total_out;
aes->stream.vtbl = &mz_stream_aes_vtbl;
aes->encryption_mode = MZ_AES_ENCRYPTIONMODE;
}
if (stream != NULL)

View File

@ -27,6 +27,7 @@ extern "C" {
/***************************************************************************/
int32_t mz_stream_aes_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_aes_is_open(void *stream);
int32_t mz_stream_aes_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_aes_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_aes_tell(void *stream);
@ -43,6 +44,8 @@ int32_t mz_stream_aes_get_footer_size(void *stream);
void* mz_stream_aes_create(void **stream);
void mz_stream_aes_delete(void **stream);
void* mz_stream_aes_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus

View File

@ -33,6 +33,21 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_buffered_vtbl = {
mz_stream_buffered_open,
mz_stream_buffered_is_open,
mz_stream_buffered_read,
mz_stream_buffered_write,
mz_stream_buffered_tell,
mz_stream_buffered_seek,
mz_stream_buffered_close,
mz_stream_buffered_error,
mz_stream_buffered_create,
mz_stream_buffered_delete
};
/***************************************************************************/
typedef struct mz_stream_buffered_s {
mz_stream stream;
char readbuf[MZ_BUF_BUFFERSIZE];
@ -352,16 +367,7 @@ void *mz_stream_buffered_create(void **stream)
if (buffered != NULL)
{
memset(buffered, 0, sizeof(mz_stream_buffered));
buffered->stream.open = mz_stream_buffered_open;
buffered->stream.read = mz_stream_buffered_read;
buffered->stream.write = mz_stream_buffered_write;
buffered->stream.tell = mz_stream_buffered_tell;
buffered->stream.seek = mz_stream_buffered_seek;
buffered->stream.close = mz_stream_buffered_close;
buffered->stream.error = mz_stream_buffered_error;
buffered->stream.create = mz_stream_buffered_create;
buffered->stream.delete = mz_stream_buffered_delete;
buffered->stream.vtbl = &mz_stream_buffered_vtbl;
}
if (stream != NULL)
*stream = buffered;
@ -379,3 +385,8 @@ void mz_stream_buffered_delete(void **stream)
free(buffered);
*stream = NULL;
}
void *mz_stream_buffered_get_interface(void)
{
return (void *)&mz_stream_buffered_vtbl;
}

View File

@ -23,6 +23,7 @@ extern "C" {
/***************************************************************************/
int32_t mz_stream_buffered_open(void *stream, const char *path, int32_t mode);
int32_t mz_stream_buffered_is_open(void *stream);
int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_buffered_tell(void *stream);
@ -33,6 +34,8 @@ int32_t mz_stream_buffered_error(void *stream);
void* mz_stream_buffered_create(void **stream);
void mz_stream_buffered_delete(void **stream);
void* mz_stream_buffered_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus

View File

@ -23,6 +23,23 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_bzip_vtbl = {
mz_stream_bzip_open,
mz_stream_bzip_is_open,
mz_stream_bzip_read,
mz_stream_bzip_write,
mz_stream_bzip_tell,
mz_stream_bzip_seek,
mz_stream_bzip_close,
mz_stream_bzip_error,
mz_stream_bzip_create,
mz_stream_bzip_delete,
mz_stream_bzip_get_total_in,
mz_stream_bzip_get_total_out
};
/***************************************************************************/
typedef struct mz_stream_bzip_s {
mz_stream stream;
bz_stream bzstream;
@ -304,19 +321,7 @@ void *mz_stream_bzip_create(void **stream)
if (bzip != NULL)
{
memset(bzip, 0, sizeof(mz_stream_bzip));
bzip->stream.open = mz_stream_bzip_open;
bzip->stream.is_open = mz_stream_bzip_is_open;
bzip->stream.read = mz_stream_bzip_read;
bzip->stream.write = mz_stream_bzip_write;
bzip->stream.tell = mz_stream_bzip_tell;
bzip->stream.seek = mz_stream_bzip_seek;
bzip->stream.close = mz_stream_bzip_close;
bzip->stream.error = mz_stream_bzip_error;
bzip->stream.create = mz_stream_bzip_create;
bzip->stream.delete = mz_stream_bzip_delete;
bzip->stream.get_total_in = mz_stream_bzip_get_total_in;
bzip->stream.get_total_out = mz_stream_bzip_get_total_out;
bzip->stream.vtbl = &mz_stream_bzip_vtbl;
bzip->level = 6;
}
if (stream != NULL)
@ -336,6 +341,11 @@ void mz_stream_bzip_delete(void **stream)
*stream = NULL;
}
void *mz_stream_bzip_get_interface(void)
{
return (void *)&mz_stream_bzip_vtbl;
}
extern void bz_internal_error(int errcode)
{
}

View File

@ -21,6 +21,7 @@ extern "C" {
/***************************************************************************/
int32_t mz_stream_bzip_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_bzip_is_open(void *stream);
int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_bzip_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_bzip_tell(void *stream);
@ -36,6 +37,8 @@ void mz_stream_bzip_set_max_total_in(void *stream, int64_t max_total_in);
void* mz_stream_bzip_create(void **stream);
void mz_stream_bzip_delete(void **stream);
void* mz_stream_bzip_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus

View File

@ -43,6 +43,23 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_crypt_vtbl = {
mz_stream_crypt_open,
mz_stream_crypt_is_open,
mz_stream_crypt_read,
mz_stream_crypt_write,
mz_stream_crypt_tell,
mz_stream_crypt_seek,
mz_stream_crypt_close,
mz_stream_crypt_error,
mz_stream_crypt_create,
mz_stream_crypt_delete,
mz_stream_crypt_get_total_in,
mz_stream_crypt_get_total_out
};
/***************************************************************************/
typedef struct mz_stream_crypt_s {
mz_stream stream;
uint32_t keys[3]; // keys defining the pseudo-random sequence
@ -278,19 +295,7 @@ void *mz_stream_crypt_create(void **stream)
if (crypt != NULL)
{
memset(crypt, 0, sizeof(mz_stream_crypt));
crypt->stream.open = mz_stream_crypt_open;
crypt->stream.is_open = mz_stream_crypt_is_open;
crypt->stream.read = mz_stream_crypt_read;
crypt->stream.write = mz_stream_crypt_write;
crypt->stream.tell = mz_stream_crypt_tell;
crypt->stream.seek = mz_stream_crypt_seek;
crypt->stream.close = mz_stream_crypt_close;
crypt->stream.error = mz_stream_crypt_error;
crypt->stream.create = mz_stream_crypt_create;
crypt->stream.delete = mz_stream_crypt_delete;
crypt->stream.get_total_in = mz_stream_crypt_get_total_in;
crypt->stream.get_total_out = mz_stream_crypt_get_total_out;
crypt->stream.vtbl = &mz_stream_crypt_vtbl;
}
if (stream != NULL)
@ -308,3 +313,8 @@ void mz_stream_crypt_delete(void **stream)
free(crypt);
*stream = NULL;
}
void *mz_stream_crypt_get_interface(void)
{
return (void *)&mz_stream_crypt_vtbl;
}

View File

@ -29,6 +29,7 @@ extern "C" {
/***************************************************************************/
int32_t mz_stream_crypt_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_crypt_is_open(void *stream);
int32_t mz_stream_crypt_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_crypt_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_crypt_tell(void *stream);
@ -45,6 +46,8 @@ int64_t mz_stream_crypt_get_total_out(void *stream);
void* mz_stream_crypt_create(void **stream);
void mz_stream_crypt_delete(void **stream);
void* mz_stream_crypt_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus

View File

@ -34,6 +34,23 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_lzma_vtbl = {
mz_stream_lzma_open,
mz_stream_lzma_is_open,
mz_stream_lzma_read,
mz_stream_lzma_write,
mz_stream_lzma_tell,
mz_stream_lzma_seek,
mz_stream_lzma_close,
mz_stream_lzma_error,
mz_stream_lzma_create,
mz_stream_lzma_delete,
mz_stream_lzma_get_total_in,
mz_stream_lzma_get_total_out
};
/***************************************************************************/
typedef struct mz_stream_lzma_s {
mz_stream stream;
lzma_stream lstream;
@ -327,19 +344,7 @@ void *mz_stream_lzma_create(void **stream)
if (lzma != NULL)
{
memset(lzma, 0, sizeof(mz_stream_lzma));
lzma->stream.open = mz_stream_lzma_open;
lzma->stream.is_open = mz_stream_lzma_is_open;
lzma->stream.read = mz_stream_lzma_read;
lzma->stream.write = mz_stream_lzma_write;
lzma->stream.tell = mz_stream_lzma_tell;
lzma->stream.seek = mz_stream_lzma_seek;
lzma->stream.close = mz_stream_lzma_close;
lzma->stream.error = mz_stream_lzma_error;
lzma->stream.create = mz_stream_lzma_create;
lzma->stream.delete = mz_stream_lzma_delete;
lzma->stream.get_total_in = mz_stream_lzma_get_total_in;
lzma->stream.get_total_out = mz_stream_lzma_get_total_out;
lzma->stream.vtbl = &mz_stream_lzma_vtbl;
lzma->preset = LZMA_PRESET_DEFAULT;
}
if (stream != NULL)
@ -358,3 +363,8 @@ void mz_stream_lzma_delete(void **stream)
free(lzma);
*stream = NULL;
}
void *mz_stream_lzma_get_interface(void)
{
return (void *)&mz_stream_lzma_vtbl;
}

View File

@ -21,6 +21,7 @@ extern "C" {
/***************************************************************************/
int32_t mz_stream_lzma_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_lzma_is_open(void *stream);
int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_lzma_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_lzma_tell(void *stream);
@ -36,6 +37,8 @@ void mz_stream_lzma_set_max_total_in(void *stream, int64_t max_total_in);
void* mz_stream_lzma_create(void **stream);
void mz_stream_lzma_delete(void **stream);
void* mz_stream_lzma_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus

View File

@ -28,6 +28,21 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_mem_vtbl = {
mz_stream_mem_open,
mz_stream_mem_is_open,
mz_stream_mem_read,
mz_stream_mem_write,
mz_stream_mem_tell,
mz_stream_mem_seek,
mz_stream_mem_close,
mz_stream_mem_error,
mz_stream_mem_create,
mz_stream_mem_delete
};
/***************************************************************************/
typedef struct mz_stream_mem_s {
mz_stream stream;
char *buffer; // Memory buffer pointer
@ -214,17 +229,7 @@ void *mz_stream_mem_create(void **stream)
if (mem != NULL)
{
memset(mem, 0, sizeof(mz_stream_mem));
mem->stream.open = mz_stream_mem_open;
mem->stream.is_open = mz_stream_mem_is_open;
mem->stream.read = mz_stream_mem_read;
mem->stream.write = mz_stream_mem_write;
mem->stream.tell = mz_stream_mem_tell;
mem->stream.seek = mz_stream_mem_seek;
mem->stream.close = mz_stream_mem_close;
mem->stream.error = mz_stream_mem_error;
mem->stream.create = mz_stream_mem_create;
mem->stream.delete = mz_stream_mem_delete;
mem->stream.vtbl = &mz_stream_mem_vtbl;
mem->grow_size = 16384;
}
if (stream != NULL)
@ -246,4 +251,9 @@ void mz_stream_mem_delete(void **stream)
free(mem);
}
*stream = NULL;
}
void *mz_stream_mem_get_interface(void)
{
return (void *)&mz_stream_mem_vtbl;
}

View File

@ -22,6 +22,7 @@ extern "C" {
/***************************************************************************/
int32_t mz_stream_mem_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_mem_is_open(void *stream);
int32_t mz_stream_mem_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_mem_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_mem_tell(void *stream);
@ -38,6 +39,8 @@ void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size);
void* mz_stream_mem_create(void **stream);
void mz_stream_mem_delete(void **stream);
void* mz_stream_mem_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus

View File

@ -61,9 +61,24 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_posix_vtbl = {
mz_stream_posix_open,
mz_stream_posix_is_open,
mz_stream_posix_read,
mz_stream_posix_write,
mz_stream_posix_tell,
mz_stream_posix_seek,
mz_stream_posix_close,
mz_stream_posix_error,
mz_stream_posix_create,
mz_stream_posix_delete
};
/***************************************************************************/
typedef struct mz_stream_posix_s
{
mz_stream stream;
mz_stream *stream;
FILE *handle;
int16_t error;
} mz_stream_posix;
@ -195,18 +210,7 @@ void *mz_stream_posix_create(void **stream)
posix = (mz_stream_posix *)malloc(sizeof(mz_stream_posix));
if (posix != NULL)
{
posix->stream.open = mz_stream_posix_open;
posix->stream.is_open = mz_stream_posix_is_open;
posix->stream.read = mz_stream_posix_read;
posix->stream.write = mz_stream_posix_write;
posix->stream.tell = mz_stream_posix_tell;
posix->stream.seek = mz_stream_posix_seek;
posix->stream.close = mz_stream_posix_close;
posix->stream.error = mz_stream_posix_error;
posix->stream.create = mz_stream_posix_create;
posix->stream.delete = mz_stream_posix_delete;
}
posix->stream.vtbl = &mz_stream_posix_i;
if (stream != NULL)
*stream = posix;
@ -223,3 +227,8 @@ void mz_stream_posix_delete(void **stream)
free(posix);
*stream = NULL;
}
void *mz_stream_posix_get_interface(void)
{
return (void *)&mz_stream_posix_i;
}

View File

@ -37,6 +37,8 @@ int32_t mz_stream_posix_error(void *stream);
void* mz_stream_posix_create(void **stream);
void mz_stream_posix_delete(void **stream);
void* mz_stream_posix_get_interface(void);
/***************************************************************************/
#if !defined(_WIN32) && !defined(USEWIN32IOAPI)

View File

@ -40,11 +40,26 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_win32_vtbl = {
mz_stream_win32_open,
mz_stream_win32_is_open,
mz_stream_win32_read,
mz_stream_win32_write,
mz_stream_win32_tell,
mz_stream_win32_seek,
mz_stream_win32_close,
mz_stream_win32_error,
mz_stream_win32_create,
mz_stream_win32_delete
};
/***************************************************************************/
typedef struct mz_stream_win32_s
{
mz_stream stream;
HANDLE handle;
int32_t error;
mz_stream vtbl;
HANDLE handle;
int32_t error;
} mz_stream_win32;
/***************************************************************************/
@ -264,17 +279,7 @@ void *mz_stream_win32_create(void **stream)
if (win32 != NULL)
{
memset(win32, 0, sizeof(mz_stream_win32));
win32->stream.open = mz_stream_win32_open;
win32->stream.is_open = mz_stream_win32_is_open;
win32->stream.read = mz_stream_win32_read;
win32->stream.write = mz_stream_win32_write;
win32->stream.tell = mz_stream_win32_tell;
win32->stream.seek = mz_stream_win32_seek;
win32->stream.close = mz_stream_win32_close;
win32->stream.error = mz_stream_win32_error;
win32->stream.create = mz_stream_win32_create;
win32->stream.delete = mz_stream_win32_delete;
win32->stream.vtbl = &mz_stream_win32_vtbl;
}
if (stream != NULL)
*stream = win32;
@ -292,3 +297,8 @@ void mz_stream_win32_delete(void **stream)
free(win32);
*stream = NULL;
}
void *mz_stream_win32_get_interface(void)
{
return (void *)&mz_stream_win32_vtbl;
}

View File

@ -37,6 +37,8 @@ int32_t mz_stream_win32_error(void *stream);
void* mz_stream_win32_create(void **stream);
void mz_stream_win32_delete(void **stream);
void* mz_stream_win32_get_interface(void);
/***************************************************************************/
#if defined(_WIN32) || defined(USEWIN32IOAPI)

View File

@ -33,6 +33,23 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_zlib_vtbl = {
mz_stream_zlib_open,
mz_stream_zlib_is_open,
mz_stream_zlib_read,
mz_stream_zlib_write,
mz_stream_zlib_tell,
mz_stream_zlib_seek,
mz_stream_zlib_close,
mz_stream_zlib_error,
mz_stream_zlib_create,
mz_stream_zlib_delete,
mz_stream_zlib_get_total_in,
mz_stream_zlib_get_total_out
};
/***************************************************************************/
typedef struct mz_stream_zlib_s {
mz_stream stream;
z_stream zstream;
@ -343,19 +360,7 @@ void *mz_stream_zlib_create(void **stream)
if (zlib != NULL)
{
memset(zlib, 0, sizeof(mz_stream_zlib));
zlib->stream.open = mz_stream_zlib_open;
zlib->stream.is_open = mz_stream_zlib_is_open;
zlib->stream.read = mz_stream_zlib_read;
zlib->stream.write = mz_stream_zlib_write;
zlib->stream.tell = mz_stream_zlib_tell;
zlib->stream.seek = mz_stream_zlib_seek;
zlib->stream.close = mz_stream_zlib_close;
zlib->stream.error = mz_stream_zlib_error;
zlib->stream.create = mz_stream_zlib_create;
zlib->stream.delete = mz_stream_zlib_delete;
zlib->stream.get_total_in = mz_stream_zlib_get_total_in;
zlib->stream.get_total_out = mz_stream_zlib_get_total_out;
zlib->stream.vtbl = &mz_stream_zlib_vtbl;
zlib->level = Z_DEFAULT_COMPRESSION;
zlib->window_bits = -MAX_WBITS;
zlib->mem_level = DEF_MEM_LEVEL;
@ -378,6 +383,28 @@ void mz_stream_zlib_delete(void **stream)
*stream = NULL;
}
void *mz_stream_zlib_get_interface(void)
{
return (void *)&mz_stream_zlib_vtbl;
}
/***************************************************************************/
mz_stream_vtbl mz_stream_crc32_vtbl = {
mz_stream_crc32_open,
mz_stream_crc32_is_open,
mz_stream_crc32_read,
mz_stream_crc32_write,
mz_stream_crc32_tell,
mz_stream_crc32_seek,
mz_stream_crc32_close,
mz_stream_crc32_error,
mz_stream_crc32_create,
mz_stream_crc32_delete,
mz_stream_crc32_get_total_in,
mz_stream_crc32_get_total_out
};
/***************************************************************************/
typedef struct mz_stream_crc32_s {
@ -409,7 +436,8 @@ int32_t mz_stream_crc32_is_open(void *stream)
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size)
{
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
int32_t read = mz_stream_read(crc32x->stream.base, buf, size);
int32_t read = 0;
read = mz_stream_read(crc32x->stream.base, buf, size);
if (read > 0)
crc32x->value = (int32_t)crc32(crc32x->value, buf, read);
crc32x->total_in += read;
@ -477,19 +505,7 @@ void *mz_stream_crc32_create(void **stream)
if (crc32 != NULL)
{
memset(crc32, 0, sizeof(mz_stream_crc32));
crc32->stream.open = mz_stream_crc32_open;
crc32->stream.is_open = mz_stream_crc32_is_open;
crc32->stream.read = mz_stream_crc32_read;
crc32->stream.write = mz_stream_crc32_write;
crc32->stream.tell = mz_stream_crc32_tell;
crc32->stream.seek = mz_stream_crc32_seek;
crc32->stream.close = mz_stream_crc32_close;
crc32->stream.error = mz_stream_crc32_error;
crc32->stream.create = mz_stream_crc32_create;
crc32->stream.delete = mz_stream_crc32_delete;
crc32->stream.get_total_in = mz_stream_crc32_get_total_in;
crc32->stream.get_total_out = mz_stream_crc32_get_total_out;
crc32->stream.vtbl = &mz_stream_crc32_vtbl;
}
if (stream != NULL)
*stream = crc32;
@ -507,3 +523,8 @@ void mz_stream_crc32_delete(void **stream)
free(crc32);
*stream = NULL;
}
void *mz_stream_crc32_get_interface(void)
{
return (void *)&mz_stream_crc32_vtbl;
}

View File

@ -21,6 +21,7 @@ extern "C" {
/***************************************************************************/
int32_t mz_stream_zlib_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_zlib_is_open(void *stream);
int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_zlib_tell(void *stream);
@ -39,9 +40,12 @@ void mz_stream_zlib_set_max_total_in(void *stream, int64_t max_total_in);
void* mz_stream_zlib_create(void **stream);
void mz_stream_zlib_delete(void **stream);
void* mz_stream_zlib_get_interface(void);
/***************************************************************************/
int32_t mz_stream_crc32_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_crc32_is_open(void *stream);
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_crc32_tell(void *stream);
@ -56,6 +60,8 @@ int64_t mz_stream_crc32_get_total_out(void *stream);
void* mz_stream_crc32_create(void **stream);
void mz_stream_crc32_delete(void **stream);
void* mz_stream_crc32_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus