summaryrefslogtreecommitdiffstats
path: root/src/gzip.c
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-05-02 20:06:51 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-05-02 20:06:51 (EDT)
commit1e0e318b510dcd886b303f23f12652b60f1eb5b9 (patch)
treed068dfe4ba2ff42ec8a12298be4526ccf3d48928 /src/gzip.c
parentf15f087cb77d44d8594836b353e5a77b1faeba28 (diff)
gzip: Fix flushing
deflate() apparently must be called with avail_in=0 and Z_FINISH after processing all input, not with Z_FINISH on the last non-empty input buffer.
Diffstat (limited to 'src/gzip.c')
-rw-r--r--src/gzip.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/gzip.c b/src/gzip.c
index 736cbd7..1263ffc 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -174,8 +174,8 @@ opkg_opk_gzip_read(struct opkg_opk_gzip *gzip, void *record)
}
}
-int
-opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size,
+static int
+_opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size,
int last)
{
/* Sanity check */
@@ -223,6 +223,16 @@ opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size,
}
int
+opkg_opk_gzip_write(struct opkg_opk_gzip *gzip, void *record, size_t size)
+{
+ if (_opkg_opk_gzip_write(gzip, record, size, 0) == OPKG_OPK_OK) {
+ return OPKG_OPK_OK;
+ } else {
+ return OPKG_OPK_ERROR;
+ }
+}
+
+int
opkg_opk_gzip_free(struct opkg_opk_gzip *gzip)
{
int ret;
@@ -233,6 +243,9 @@ opkg_opk_gzip_free(struct opkg_opk_gzip *gzip)
ret = OPKG_OPK_ERROR;
}
} else {
+ if (_opkg_opk_gzip_write(gzip, NULL, 0, 1) != OPKG_OPK_END) {
+ ret = OPKG_OPK_ERROR;
+ }
if (deflateEnd(&gzip->stream) != Z_OK) {
ret = OPKG_OPK_ERROR;
}