summaryrefslogtreecommitdiff
path: root/src/compress.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/compress.c')
-rw-r--r--src/compress.c16
1 files changed, 10 insertions, 6 deletions
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)