]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
minigzip: Use bigger buffer for writing.
authorMika Lindqvist <postmaster@raasu.org>
Sun, 22 Nov 2015 21:40:57 +0000 (23:40 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Wed, 25 Nov 2015 12:45:40 +0000 (13:45 +0100)
test/minigzip.c

index 7279c0af9a05b447f82416097de30c9cc2b80a3a..5ea57100fe2047e68c86b5b4f3dde9c6a3559d56 100644 (file)
@@ -49,7 +49,8 @@
 #endif
 #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
 
-#define BUFLEN      16384
+#define BUFLEN      16384        /* read buffer size */
+#define BUFLENW     (BUFLEN * 3) /* write buffer size */
 #define MAX_NAME_LEN 1024
 
 #ifndef WITH_GZFILEOP
@@ -111,7 +112,7 @@ gzFile gz_open(const char *path, int fd, const char *mode)
     gz->strm.zalloc = myalloc;
     gz->strm.zfree = myfree;
     gz->strm.opaque = Z_NULL;
-    gz->buf = malloc(BUFLEN);
+    gz->buf = malloc(gz->write ? BUFLENW : BUFLEN);
 
     if (gz->buf == NULL) {
         free(gz);
@@ -161,9 +162,9 @@ int gzwrite(gzFile gz, const void *buf, unsigned len)
     strm->avail_in = len;
     do {
         strm->next_out = gz->buf;
-        strm->avail_out = BUFLEN;
+        strm->avail_out = BUFLENW;
         (void)deflate(strm, Z_NO_FLUSH);
-        fwrite(gz->buf, 1, BUFLEN - strm->avail_out, gz->file);
+        fwrite(gz->buf, 1, BUFLENW - strm->avail_out, gz->file);
     } while (strm->avail_out == 0);
     return len;
 }
@@ -216,9 +217,9 @@ int gzclose(gzFile gz)
         strm->avail_in = 0;
         do {
             strm->next_out = gz->buf;
-            strm->avail_out = BUFLEN;
+            strm->avail_out = BUFLENW;
             (void)deflate(strm, Z_FINISH);
-            fwrite(gz->buf, 1, BUFLEN - strm->avail_out, gz->file);
+            fwrite(gz->buf, 1, BUFLENW - strm->avail_out, gz->file);
         } while (strm->avail_out == 0);
         deflateEnd(strm);
     }
@@ -331,7 +332,7 @@ int gz_compress_mmap(FILE   *in, gzFile out)
  */
 void gz_uncompress(gzFile in, FILE   *out)
 {
-    char buf[BUFLEN];
+    char buf[BUFLENW];
     int len;
     int err;