mirror of
https://github.com/libretro/RetroArch
synced 2025-03-02 19:13:34 +00:00
Add stream_decompress_data_to_file_init and stream-decompress_data_to_file_iterate to
file_archive_zlib.c
This commit is contained in:
parent
fe1cbe6a5a
commit
1a04bb4532
@ -395,11 +395,12 @@ static int zip_file_decompressed(const char *name, const char *valid_exts,
|
||||
{
|
||||
int ret = 0;
|
||||
zlib_file_handle_t handle = {0};
|
||||
if (!file_archive_inflate_data_to_file_init(&handle, cdata, csize, size))
|
||||
handle.backend = file_archive_get_default_file_backend();
|
||||
if (!handle.backend->stream_decompress_data_to_file_init(&handle, cdata, csize, size))
|
||||
return false;
|
||||
|
||||
do{
|
||||
ret = file_archive_inflate_data_to_file_iterate(handle.stream);
|
||||
ret = handle.backend->stream_decompress_data_to_file_iterate(handle.stream);
|
||||
}while(ret == 0);
|
||||
|
||||
handle.real_checksum = file_archive_crc32_calculate(0, handle.data, size);
|
||||
|
@ -412,68 +412,6 @@ void zlib_deflate_init(void *data, int level)
|
||||
deflateInit(stream, level);
|
||||
}
|
||||
|
||||
bool file_archive_inflate_data_to_file_init(
|
||||
zlib_file_handle_t *handle,
|
||||
const uint8_t *cdata, uint32_t csize, uint32_t size)
|
||||
{
|
||||
z_stream *stream = NULL;
|
||||
|
||||
if (!handle)
|
||||
return false;
|
||||
|
||||
if (!handle->backend)
|
||||
handle->backend = file_archive_get_default_file_backend();
|
||||
|
||||
if (!(handle->stream = (z_stream*)handle->backend->stream_new()))
|
||||
goto error;
|
||||
|
||||
if (inflateInit2(handle->stream, -MAX_WBITS) != Z_OK)
|
||||
goto error;
|
||||
|
||||
handle->data = (uint8_t*)malloc(size);
|
||||
|
||||
if (!handle->data)
|
||||
goto error;
|
||||
|
||||
stream = (z_stream*)handle->stream;
|
||||
|
||||
if (!stream)
|
||||
goto error;
|
||||
|
||||
handle->backend->stream_set(stream, csize, size,
|
||||
(const uint8_t*)cdata, handle->data);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
if (handle->stream)
|
||||
handle->backend->stream_free(handle->stream);
|
||||
free(handle->stream);
|
||||
if (handle->data)
|
||||
free(handle->data);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int file_archive_inflate_data_to_file_iterate(void *data)
|
||||
{
|
||||
int zstatus;
|
||||
z_stream *stream = (z_stream*)data;
|
||||
|
||||
if (!stream)
|
||||
return -1;
|
||||
|
||||
zstatus = inflate(stream, Z_NO_FLUSH);
|
||||
|
||||
if (zstatus == Z_STREAM_END)
|
||||
return 1;
|
||||
|
||||
if (zstatus != Z_OK && zstatus != Z_BUF_ERROR)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t file_archive_crc32_calculate(
|
||||
uint32_t crc,
|
||||
const uint8_t *data,
|
||||
@ -750,12 +688,14 @@ bool file_archive_perform_mode(const char *path, const char *valid_exts,
|
||||
{
|
||||
int ret = 0;
|
||||
zlib_file_handle_t handle = {0};
|
||||
if (!file_archive_inflate_data_to_file_init(&handle,
|
||||
handle.backend = file_archive_get_default_file_backend();
|
||||
|
||||
if (!handle.backend->stream_decompress_data_to_file_init(&handle,
|
||||
cdata, csize, size))
|
||||
return false;
|
||||
|
||||
do{
|
||||
ret = file_archive_inflate_data_to_file_iterate(handle.stream);
|
||||
ret = handle.backend->stream_decompress_data_to_file_iterate(handle.stream);
|
||||
}while(ret == 0);
|
||||
|
||||
if (!file_archive_inflate_data_to_file(&handle,
|
||||
|
@ -129,6 +129,64 @@ static bool zlib_stream_decompress_init(void *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool zlib_stream_decompress_data_to_file_init(
|
||||
zlib_file_handle_t *handle,
|
||||
const uint8_t *cdata, uint32_t csize, uint32_t size)
|
||||
{
|
||||
z_stream *stream = NULL;
|
||||
|
||||
if (!handle)
|
||||
return false;
|
||||
|
||||
if (!(handle->stream = (z_stream*)zlib_stream_new()))
|
||||
goto error;
|
||||
|
||||
if (inflateInit2(handle->stream, -MAX_WBITS) != Z_OK)
|
||||
goto error;
|
||||
|
||||
handle->data = (uint8_t*)malloc(size);
|
||||
|
||||
if (!handle->data)
|
||||
goto error;
|
||||
|
||||
stream = (z_stream*)handle->stream;
|
||||
|
||||
if (!stream)
|
||||
goto error;
|
||||
|
||||
zlib_stream_set(stream, csize, size,
|
||||
(const uint8_t*)cdata, handle->data);
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
zlib_stream_free(handle->stream);
|
||||
free(handle->stream);
|
||||
if (handle->data)
|
||||
free(handle->data);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int zlib_stream_decompress_data_to_file_iterate(void *data)
|
||||
{
|
||||
int zstatus;
|
||||
z_stream *stream = (z_stream*)data;
|
||||
|
||||
if (!stream)
|
||||
return -1;
|
||||
|
||||
zstatus = inflate(stream, Z_NO_FLUSH);
|
||||
|
||||
if (zstatus == Z_STREAM_END)
|
||||
return 1;
|
||||
|
||||
if (zstatus != Z_OK && zstatus != Z_BUF_ERROR)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct zlib_file_backend zlib_backend = {
|
||||
zlib_stream_new,
|
||||
zlib_stream_free,
|
||||
@ -138,6 +196,8 @@ const struct zlib_file_backend zlib_backend = {
|
||||
zlib_stream_get_total_out,
|
||||
zlib_stream_decrement_total_out,
|
||||
zlib_stream_decompress_init,
|
||||
zlib_stream_decompress_data_to_file_init,
|
||||
zlib_stream_decompress_data_to_file_iterate,
|
||||
zlib_stream_compress_free,
|
||||
zlib_stream_compress_data_to_file,
|
||||
"zlib"
|
||||
|
@ -699,7 +699,7 @@ static int rpng_load_image_argb_process_inflate_init(rpng_t *rpng,
|
||||
if (!to_continue)
|
||||
goto end;
|
||||
|
||||
zstatus = file_archive_inflate_data_to_file_iterate(rpng->process.stream);
|
||||
zstatus = rpng->process.stream_backend->stream_decompress_data_to_file_iterate(rpng->process.stream);
|
||||
|
||||
switch (zstatus)
|
||||
{
|
||||
|
@ -37,6 +37,14 @@ enum zlib_transfer_type
|
||||
ZLIB_TRANSFER_DEINIT_ERROR
|
||||
};
|
||||
|
||||
typedef struct zlib_handle
|
||||
{
|
||||
void *stream;
|
||||
uint8_t *data;
|
||||
uint32_t real_checksum;
|
||||
const struct zlib_file_backend *backend;
|
||||
} zlib_file_handle_t;
|
||||
|
||||
struct zlib_file_backend
|
||||
{
|
||||
void *(*stream_new)(void);
|
||||
@ -48,6 +56,9 @@ struct zlib_file_backend
|
||||
uint64_t (*stream_get_total_out)(void*);
|
||||
void (*stream_decrement_total_out)(void *, unsigned);
|
||||
bool (*stream_decompress_init)(void *);
|
||||
bool (*stream_decompress_data_to_file_init)(
|
||||
zlib_file_handle_t *, const uint8_t *, uint32_t, uint32_t);
|
||||
int (*stream_decompress_data_to_file_iterate)(void *data);
|
||||
void (*stream_compress_free)(void *);
|
||||
int (*stream_compress_data_to_file)(void *);
|
||||
const char *ident;
|
||||
@ -64,13 +75,6 @@ typedef struct zlib_transfer
|
||||
const struct zlib_file_backend *backend;
|
||||
} zlib_transfer_t;
|
||||
|
||||
typedef struct zlib_handle
|
||||
{
|
||||
void *stream;
|
||||
uint8_t *data;
|
||||
uint32_t real_checksum;
|
||||
const struct zlib_file_backend *backend;
|
||||
} zlib_file_handle_t;
|
||||
|
||||
/* Returns true when parsing should continue. False to stop. */
|
||||
typedef int (*file_archive_file_cb)(const char *name, const char *valid_exts,
|
||||
@ -133,12 +137,6 @@ bool file_archive_extract_first_content_file(char *zip_path, size_t zip_path_siz
|
||||
**/
|
||||
struct string_list *file_archive_get_file_list(const char *path, const char *valid_exts);
|
||||
|
||||
bool file_archive_inflate_data_to_file_init(
|
||||
zlib_file_handle_t *handle,
|
||||
const uint8_t *cdata, uint32_t csize, uint32_t size);
|
||||
|
||||
int file_archive_inflate_data_to_file_iterate(void *data);
|
||||
|
||||
/**
|
||||
* file_archive_inflate_data_to_file:
|
||||
* @path : filename path of archive.
|
||||
|
Loading…
x
Reference in New Issue
Block a user