Create stream_compress_free and add it to file_archive_zlib

This commit is contained in:
twinaphex 2016-01-24 20:12:12 +01:00
parent f264d3d29b
commit d1ef6f032e
4 changed files with 11 additions and 11 deletions

View File

@ -434,13 +434,6 @@ bool file_archive_inflate_init(void *data)
return true;
}
void zlib_stream_deflate_free(void *data)
{
z_stream *ret = (z_stream*)data;
if (ret)
deflateEnd(ret);
}
bool file_archive_inflate_data_to_file_init(
zlib_file_handle_t *handle,
const uint8_t *cdata, uint32_t csize, uint32_t size)

View File

@ -76,6 +76,13 @@ static void zlib_stream_decrement_total_out(void *data, unsigned subtraction)
stream->total_out -= subtraction;
}
static void zlib_stream_compress_free(void *data)
{
z_stream *ret = (z_stream*)data;
if (ret)
deflateEnd(ret);
}
const struct zlib_file_backend zlib_backend = {
zlib_stream_new,
zlib_stream_free,
@ -83,5 +90,6 @@ const struct zlib_file_backend zlib_backend = {
zlib_stream_get_avail_out,
zlib_stream_get_total_out,
zlib_stream_decrement_total_out,
zlib_stream_compress_free,
"zlib"
};

View File

@ -339,11 +339,11 @@ static bool rpng_save_image(const char *path,
if (zlib_deflate_data_to_file(stream) != 1)
{
zlib_stream_deflate_free(stream);
stream_backend->stream_compress_free(stream);
GOTO_END_ERROR();
}
zlib_stream_deflate_free(stream);
stream_backend->stream_compress_free(stream);
memcpy(deflate_buf + 4, "IDAT", 4);
dword_write_be(deflate_buf + 0, stream_backend->stream_get_total_out(stream));

View File

@ -45,6 +45,7 @@ struct zlib_file_backend
uint32_t (*stream_get_avail_out)(void*);
uint64_t (*stream_get_total_out)(void*);
void (*stream_decrement_total_out)(void *, unsigned);
void (*stream_compress_free)(void *);
const char *ident;
};
@ -162,8 +163,6 @@ void zlib_deflate_init(void *data, int level);
int zlib_deflate_data_to_file(void *data);
void zlib_stream_deflate_free(void *data);
bool file_archive_inflate_init(void *data);
void zlib_set_stream(void *data,