gtoubassi / femtozip

FemtoZip is a "shared dictionary" compression library optimized for small documents that may not compress well with traditional tools such as gzip
Other
146 stars 23 forks source link

Add fz_compress_writer and fz_decompress_writer to C interface #14

Closed tmthrgd closed 8 years ago

tmthrgd commented 8 years ago

This PR adds two functions fz_compress_writer and fz_decompress_writer which mirror fz_compress and fz_decompress but take a writer function rather than a destination buffer.

Where the original functions take char *dest, int dest_capacity and need a preallocated buffer, the new functions take a writer function (int (*dest_writer)(const char *buf, size_t len, void *arg)) and an argument for it.

Using these functions it may be possible (depending on the use case) to avoid the overhead of a memcpy. These functions also remove the wasteful need to call fz_compress or fz_decompress twice if the destination buffer is too small.

gtoubassi commented 8 years ago

lgtm. Thanks!