From cfd5fb6e6fb47e084e66e1e4e2d6a99f19be661e Mon Sep 17 00:00:00 2001 From: jakob Date: Tue, 6 Jun 2017 15:40:40 -0400 Subject: Cleaned up --- src/compress.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/compress.c') diff --git a/src/compress.c b/src/compress.c index e61780d..4df5ef7 100644 --- a/src/compress.c +++ b/src/compress.c @@ -26,7 +26,10 @@ #define LEVEL -1 -/* Inflates `s` into a newly allocated stream structure. */ +/* Inflates `len` bytes from the current position of `s` to a new stream + structure of size `decompressed_len` bytes. Stream inflation will not + work if `decompressed_len` does not represent the actual size of the + original data. */ struct stream *stream_inflate(struct stream *s, size_t len, size_t decompressed_len) { z_stream strm; @@ -40,17 +43,17 @@ struct stream *stream_inflate(struct stream *s, size_t len, return NULL; int ret; - struct stream *n = stream_new(decompressed_len); + struct stream *new = stream_new(decompressed_len); do { strm.avail_in = len; strm.next_in = (Bytef *) s->_cur; do { strm.avail_out = decompressed_len; - strm.next_out = (Bytef *) n->_cur; + strm.next_out = (Bytef *) new->_cur; ret = inflate(&strm, Z_NO_FLUSH); if (ret == Z_STREAM_ERROR) { - stream_free(n); + stream_free(new); inflateEnd(&strm); return NULL; } @@ -58,11 +61,12 @@ struct stream *stream_inflate(struct stream *s, size_t len, } while (ret != Z_STREAM_END); inflateEnd(&strm); - return n; + return new; } -/* Deflates `s` into a newly allocated stream structure. */ +/* Deflates `len` bytes from the current position of `s` to a new stream + structure, where the `len` member represents the decompressed size. */ struct stream *stream_deflate(struct stream *s, size_t len) { struct stream *new = stream_new(len); if (new == NULL) -- cgit v1.3