Move raw stream back to zlib.

This commit is contained in:
Nathan Moinvaziri 2017-10-20 08:37:58 -07:00
parent e220ac2679
commit caf54683a5
4 changed files with 152 additions and 152 deletions

View File

@ -286,150 +286,3 @@ void mz_stream_delete(void **stream)
strm->vtbl->delete(stream);
*stream = NULL;
}
/***************************************************************************/
typedef struct mz_stream_raw_s {
mz_stream stream;
int64_t total_in;
int64_t total_out;
int64_t max_total_in;
} mz_stream_raw;
/***************************************************************************/
int32_t mz_stream_raw_open(void *stream, const char *path, int32_t mode)
{
return MZ_OK;
}
int32_t mz_stream_raw_is_open(void *stream)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
return mz_stream_is_open(raw->stream.base);
}
int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
int32_t bytes_to_read = size;
int32_t read = 0;
if (raw->max_total_in > 0)
{
if ((raw->max_total_in - raw->total_in) < size)
bytes_to_read = (int32_t)(raw->max_total_in - raw->total_in);
}
read = mz_stream_read(raw->stream.base, buf, bytes_to_read);
if (read > 0)
raw->total_in += read;
return read;
}
int32_t mz_stream_raw_write(void *stream, const void *buf, int32_t size)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
int32_t written = mz_stream_write(raw->stream.base, buf, size);
if (written > 0)
raw->total_out += written;
return written;
}
int64_t mz_stream_raw_tell(void *stream)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
return mz_stream_tell(raw->stream.base);
}
int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
return mz_stream_seek(raw->stream.base, offset, origin);
}
int32_t mz_stream_raw_close(void *stream)
{
return MZ_OK;
}
int32_t mz_stream_raw_error(void *stream)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
return mz_stream_error(raw->stream.base);
}
int32_t mz_stream_raw_get_prop_int64(void *stream, int32_t prop, int64_t *value)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = raw->total_in;
return MZ_OK;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = raw->total_out;
return MZ_OK;
}
return MZ_EXIST_ERROR;
}
int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN_MAX:
raw->max_total_in = value;
return MZ_OK;
}
return MZ_EXIST_ERROR;
}
/***************************************************************************/
mz_stream_vtbl mz_stream_raw_vtbl = {
mz_stream_raw_open,
mz_stream_raw_is_open,
mz_stream_raw_read,
mz_stream_raw_write,
mz_stream_raw_tell,
mz_stream_raw_seek,
mz_stream_raw_close,
mz_stream_raw_error,
mz_stream_raw_create,
mz_stream_raw_delete,
mz_stream_raw_get_prop_int64,
mz_stream_raw_set_prop_int64
};
/***************************************************************************/
void *mz_stream_raw_create(void **stream)
{
mz_stream_raw *raw = NULL;
raw = (mz_stream_raw *)malloc(sizeof(mz_stream_raw));
if (raw != NULL)
{
memset(raw, 0, sizeof(mz_stream_raw));
raw->stream.vtbl = &mz_stream_raw_vtbl;
}
if (stream != NULL)
*stream = raw;
return raw;
}
void mz_stream_raw_delete(void **stream)
{
mz_stream_raw *raw = NULL;
if (stream == NULL)
return;
raw = (mz_stream_raw *)*stream;
if (raw != NULL)
free(raw);
*stream = NULL;
}

View File

@ -110,11 +110,6 @@ void mz_stream_delete(void **stream);
/***************************************************************************/
void* mz_stream_raw_create(void **stream);
void mz_stream_raw_delete(void **stream);
/***************************************************************************/
#ifdef __cplusplus
}
#endif

View File

@ -511,3 +511,150 @@ void *mz_stream_crc32_get_interface(void)
{
return (void *)&mz_stream_crc32_vtbl;
}
/***************************************************************************/
typedef struct mz_stream_raw_s {
mz_stream stream;
int64_t total_in;
int64_t total_out;
int64_t max_total_in;
} mz_stream_raw;
/***************************************************************************/
int32_t mz_stream_raw_open(void *stream, const char *path, int32_t mode)
{
return MZ_OK;
}
int32_t mz_stream_raw_is_open(void *stream)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
return mz_stream_is_open(raw->stream.base);
}
int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
int32_t bytes_to_read = size;
int32_t read = 0;
if (raw->max_total_in > 0)
{
if ((raw->max_total_in - raw->total_in) < size)
bytes_to_read = (int32_t)(raw->max_total_in - raw->total_in);
}
read = mz_stream_read(raw->stream.base, buf, bytes_to_read);
if (read > 0)
raw->total_in += read;
return read;
}
int32_t mz_stream_raw_write(void *stream, const void *buf, int32_t size)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
int32_t written = mz_stream_write(raw->stream.base, buf, size);
if (written > 0)
raw->total_out += written;
return written;
}
int64_t mz_stream_raw_tell(void *stream)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
return mz_stream_tell(raw->stream.base);
}
int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
return mz_stream_seek(raw->stream.base, offset, origin);
}
int32_t mz_stream_raw_close(void *stream)
{
return MZ_OK;
}
int32_t mz_stream_raw_error(void *stream)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
return mz_stream_error(raw->stream.base);
}
int32_t mz_stream_raw_get_prop_int64(void *stream, int32_t prop, int64_t *value)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = raw->total_in;
return MZ_OK;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = raw->total_out;
return MZ_OK;
}
return MZ_EXIST_ERROR;
}
int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value)
{
mz_stream_raw *raw = (mz_stream_raw *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN_MAX:
raw->max_total_in = value;
return MZ_OK;
}
return MZ_EXIST_ERROR;
}
/***************************************************************************/
mz_stream_vtbl mz_stream_raw_vtbl = {
mz_stream_raw_open,
mz_stream_raw_is_open,
mz_stream_raw_read,
mz_stream_raw_write,
mz_stream_raw_tell,
mz_stream_raw_seek,
mz_stream_raw_close,
mz_stream_raw_error,
mz_stream_raw_create,
mz_stream_raw_delete,
mz_stream_raw_get_prop_int64,
mz_stream_raw_set_prop_int64
};
/***************************************************************************/
void *mz_stream_raw_create(void **stream)
{
mz_stream_raw *raw = NULL;
raw = (mz_stream_raw *)malloc(sizeof(mz_stream_raw));
if (raw != NULL)
{
memset(raw, 0, sizeof(mz_stream_raw));
raw->stream.vtbl = &mz_stream_raw_vtbl;
}
if (stream != NULL)
*stream = raw;
return raw;
}
void mz_stream_raw_delete(void **stream)
{
mz_stream_raw *raw = NULL;
if (stream == NULL)
return;
raw = (mz_stream_raw *)*stream;
if (raw != NULL)
free(raw);
*stream = NULL;
}

View File

@ -59,6 +59,11 @@ void* mz_stream_crc32_get_interface(void);
/***************************************************************************/
void* mz_stream_raw_create(void **stream);
void mz_stream_raw_delete(void **stream);
/***************************************************************************/
#ifdef __cplusplus
}
#endif