inflate: Add helper for getting decompressed data size
Helper for another semi-typical operation: find out how big of a buffer should be allocated before decompressing. This can be useful when the stream container doesn't specify the decompressed size. Change-Id: I5f1536f809bb6f9bc6023120c024c3de7cea4269
This commit is contained in:
parent
ce4620413b
commit
3bd5f335f7
2 changed files with 18 additions and 0 deletions
|
@ -782,3 +782,12 @@ uint32_t inflate_buffer_writer(const void* block, uint32_t block_size, void* ctx
|
||||||
struct inflate_bufferctx* c = ctx;
|
struct inflate_bufferctx* c = ctx;
|
||||||
return inflate_buffer_rw(c, c->buf, block, block_size);
|
return inflate_buffer_rw(c, c->buf, block, block_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t inflate_getsize_writer(const void* block, uint32_t block_size, void* ctx)
|
||||||
|
{
|
||||||
|
(void)block;
|
||||||
|
|
||||||
|
size_t* size = ctx;
|
||||||
|
*size += block_size;
|
||||||
|
return block_size;
|
||||||
|
}
|
||||||
|
|
|
@ -58,4 +58,13 @@ struct inflate_bufferctx {
|
||||||
uint32_t inflate_buffer_reader(void* block, uint32_t block_size, void* ctx);
|
uint32_t inflate_buffer_reader(void* block, uint32_t block_size, void* ctx);
|
||||||
uint32_t inflate_buffer_writer(const void* block, uint32_t block_size, void* ctx);
|
uint32_t inflate_buffer_writer(const void* block, uint32_t block_size, void* ctx);
|
||||||
|
|
||||||
|
// dummy writer used if you just want to figure out how big the decompressed
|
||||||
|
// data will be. It does not actually write any data. Example usage:
|
||||||
|
//
|
||||||
|
// size_t size = 0;
|
||||||
|
// inflate(it, st, read, rctx, inflate_getsize_writer, &size);
|
||||||
|
//
|
||||||
|
// Now 'size' will be the size of the decompressed data (assuming no errors).
|
||||||
|
uint32_t inflate_getsize_writer(const void* block, uint32_t block_size, void* ctx);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue