summaryrefslogtreecommitdiff
path: root/src/compress.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2013-12-13 18:26:46 -0500
committerEdward Thomson <ethomson@microsoft.com>2014-01-14 09:45:12 -0800
commitc6f26b48e47f6c0cd67769418c33efe66e5b5fe8 (patch)
tree2c2057bb8b0b623a77d10c284c019485b65e9bb9 /src/compress.c
parentbe29dd82e27d3536b9c63f5835b102b28934555e (diff)
downloadlibgit2-c6f26b48e47f6c0cd67769418c33efe66e5b5fe8.tar.gz
Refactor zlib for easier deflate streaming
Diffstat (limited to 'src/compress.c')
-rw-r--r--src/compress.c53
1 files changed, 0 insertions, 53 deletions
diff --git a/src/compress.c b/src/compress.c
deleted file mode 100644
index 14b79404c..000000000
--- a/src/compress.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-
-#include "compress.h"
-
-#include <zlib.h>
-
-#define BUFFER_SIZE (1024 * 1024)
-
-int git__compress(git_buf *buf, const void *buff, size_t len)
-{
- z_stream zs;
- char *zb;
- size_t have;
-
- memset(&zs, 0, sizeof(zs));
- if (deflateInit(&zs, Z_DEFAULT_COMPRESSION) != Z_OK)
- return -1;
-
- zb = git__malloc(BUFFER_SIZE);
- GITERR_CHECK_ALLOC(zb);
-
- zs.next_in = (void *)buff;
- zs.avail_in = (uInt)len;
-
- do {
- zs.next_out = (unsigned char *)zb;
- zs.avail_out = BUFFER_SIZE;
-
- if (deflate(&zs, Z_FINISH) == Z_STREAM_ERROR) {
- git__free(zb);
- return -1;
- }
-
- have = BUFFER_SIZE - (size_t)zs.avail_out;
-
- if (git_buf_put(buf, zb, have) < 0) {
- git__free(zb);
- return -1;
- }
-
- } while (zs.avail_out == 0);
-
- assert(zs.avail_in == 0);
-
- deflateEnd(&zs);
- git__free(zb);
- return 0;
-}