simplify deflate checksumming code; fixes errors with upcoming 'gotadmin pack' tweak + ok naddy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
diff --git a/lib/deflate.c b/lib/deflate.c
index a9a36a6..02f9a9d 100644
--- a/lib/deflate.c
+++ b/lib/deflate.c
@@ -35,8 +35,7 @@
#endif
const struct got_error *
-got_deflate_init(struct got_deflate_buf *zb, uint8_t *outbuf, size_t bufsize,
- struct got_deflate_checksum *csum)
+got_deflate_init(struct got_deflate_buf *zb, uint8_t *outbuf, size_t bufsize)
{
const struct got_error *err = NULL;
int zerr;
@@ -74,8 +73,6 @@ got_deflate_init(struct got_deflate_buf *zb, uint8_t *outbuf, size_t bufsize,
zb->flags |= GOT_DEFLATE_F_OWN_OUTBUF;
} else
zb->outbuf = outbuf;
-
- zb->csum = csum;
done:
if (err)
got_deflate_end(zb);
@@ -104,9 +101,6 @@ got_deflate_read(struct got_deflate_buf *zb, FILE *f, size_t *outlenp)
*outlenp = 0;
do {
- char *csum_out = NULL;
- size_t csum_avail = 0;
-
if (z->avail_in == 0) {
size_t n = fread(zb->inbuf, 1, zb->inlen, f);
if (n == 0) {
@@ -119,15 +113,7 @@ got_deflate_read(struct got_deflate_buf *zb, FILE *f, size_t *outlenp)
z->next_in = zb->inbuf;
z->avail_in = n;
}
- if (zb->csum) {
- csum_out = z->next_out;
- csum_avail = z->avail_out;
- }
ret = deflate(z, Z_NO_FLUSH);
- if (zb->csum) {
- csum_output(zb->csum, csum_out,
- csum_avail - z->avail_out);
- }
} while (ret == Z_OK && z->avail_out > 0);
if (ret == Z_OK) {
@@ -159,7 +145,7 @@ got_deflate_to_file(size_t *outlen, FILE *infile, FILE *outfile,
size_t avail;
struct got_deflate_buf zb;
- err = got_deflate_init(&zb, NULL, GOT_DEFLATE_BUFSIZE, csum);
+ err = got_deflate_init(&zb, NULL, GOT_DEFLATE_BUFSIZE);
if (err)
goto done;
@@ -176,6 +162,8 @@ got_deflate_to_file(size_t *outlen, FILE *infile, FILE *outfile,
err = got_ferror(outfile, GOT_ERR_IO);
goto done;
}
+ if (csum)
+ csum_output(csum, zb.outbuf, avail);
*outlen += avail;
}
} while (zb.flags & GOT_DEFLATE_F_HAVE_MORE);
diff --git a/lib/got_lib_deflate.h b/lib/got_lib_deflate.h
index c359d7c..bb41647 100644
--- a/lib/got_lib_deflate.h
+++ b/lib/got_lib_deflate.h
@@ -31,13 +31,12 @@ struct got_deflate_buf {
int flags;
#define GOT_DEFLATE_F_HAVE_MORE 0x01
#define GOT_DEFLATE_F_OWN_OUTBUF 0x02
- struct got_deflate_checksum *csum;
};
#define GOT_DEFLATE_BUFSIZE 8192
const struct got_error *got_deflate_init(struct got_deflate_buf *, uint8_t *,
- size_t, struct got_deflate_checksum *);
+ size_t);
const struct got_error *got_deflate_read(struct got_deflate_buf *, FILE *,
size_t *);
void got_deflate_end(struct got_deflate_buf *);