Re: [PATCH 04/32] move do_compress() from pack-objects.c to pack-write.c
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Aug 24, 2010, 23:25 UTC
- Message-ID
- <20100824232554.GF2376@burratino>
- In-Reply-To
- <1282688422-7738-5-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy wrote:
> Subject: [PATCH 04/32] move do_compress() from pack-objects.c to pack-write.c
exposing it as internal API. Makes sense.
Show 24 quoted lines
> +unsigned long compress_object(void **pptr, unsigned long size)
> +{
> + z_stream stream;
> + void *in, *out;
> + unsigned long maxsize;
> +
> + memset(&stream, 0, sizeof(stream));
> + deflateInit(&stream, Z_DEFAULT_COMPRESSION);
> + maxsize = deflateBound(&stream, size);
> +
> + in = *pptr;
> + out = xmalloc(maxsize);
> + *pptr = out;
> +
> + stream.next_in = in;
> + stream.avail_in = size;
> + stream.next_out = out;
> + stream.avail_out = maxsize;
> + while (deflate(&stream, Z_FINISH) == Z_OK)
> + ; /* nothing */
> + deflateEnd(&stream);
> +
> + return stream.total_out;
> +}However, there is nothing particularly specialized to git objects about this. e.g. deflate_it() from diff.c could use this.