mirror of
https://github.com/zlib-ng/minizip-ng
synced 2025-03-28 21:13:18 +00:00
Move raw stream back to zlib.
This commit is contained in:
parent
e220ac2679
commit
caf54683a5
147
src/mz_strm.c
147
src/mz_strm.c
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user