# [PATCH 3/5] Use new decompress helpers in index-pack.c

1 messages from 2008-01-10 to 2008-01-10. Participants: Marco Costalba.
Thread: https://gitlist.dev/t/11569

## Marco Costalba, 2008-01-10 21:07

Subject: [PATCH 3/5] Use new decompress helpers in index-pack.c
Message-ID: <e5bfff550801101307g1675b94an46c25d9de03d2b46@mail.gmail.com>
URL: https://gitlist.dev/e/e5bfff550801101307g1675b94an46c25d9de03d2b46%40mail.gmail.com

```
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
---
 index-pack.c |   20 +++-----------------
 1 files changed, 3 insertions(+), 17 deletions(-)

diff --git a/index-pack.c b/index-pack.c
index 9fd6982..3c4ea51 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "compress.h"
 #include "delta.h"
 #include "pack.h"
 #include "csum-file.h"
@@ -494,24 +495,9 @@ static void parse_pack_objects(unsigned char *sha1)

 static int write_compressed(int fd, void *in, unsigned int size,
uint32_t *obj_crc)
 {
-	z_stream stream;
-	unsigned long maxsize;
-	void *out;
+	unsigned char *out = NULL;

-	memset(&stream, 0, sizeof(stream));
-	deflateInit(&stream, zlib_compression_level);
-	maxsize = deflateBound(&stream, size);
-	out = xmalloc(maxsize);
-
-	/* Compress it */
-	stream.next_in = in;
-	stream.avail_in = size;
-	stream.next_out = out;
-	stream.avail_out = maxsize;
-	while (deflate(&stream, Z_FINISH) == Z_OK);
-	deflateEnd(&stream);
-
-	size = stream.total_out;
+	size = z_deflate_all(zlib_compression_level, in, size, &out);
 	write_or_die(fd, out, size);
 	*obj_crc = crc32(*obj_crc, out, size);
 	free(out);
-- 
1.5.4.rc2.89.g1b3f

```
