src/hg/oneShot/freen/freen.c 1.90

1.90 2009/11/10 01:21:14 kent
Testing zlib compress and uncompress.
Index: src/hg/oneShot/freen/freen.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/oneShot/freen/freen.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -b -B -U 1000000 -r1.89 -r1.90
--- src/hg/oneShot/freen/freen.c	14 Sep 2009 18:13:15 -0000	1.89
+++ src/hg/oneShot/freen/freen.c	10 Nov 2009 01:21:14 -0000	1.90
@@ -1,37 +1,50 @@
 /* freen - My Pet Freen. */
 #include "common.h"
+#include <zlib.h>
 #include "memalloc.h"
 #include "dystring.h"
 #include "linefile.h"
 #include "hash.h"
+#include "obscure.h"
 
 
 static char const rcsid[] = "$Id$";
 
 void usage()
 {
 errAbort("freen - test some hairbrained thing.\n"
          "usage:  freen file\n");
 }
 
 
-void freen(char *input)
+void freen(char *input, char *output, char *uncompressed)
 /* Test some hair-brained thing. */
 {
-struct tm tm;
-ZeroVar(&tm);
-char *res = strptime(input, "%d/%b/%Y:%T", &tm);
-time_t tick = mktime(&tm);
-printf("res = %s\n", res);
-printf("%ld ticks\n", (long)tick);
-printf("%s\n", asctime(&tm));
+size_t uncompressedSize;
+char *uncompressedBuf;
+readInGulp(input, &uncompressedBuf, &uncompressedSize);
+uLongf maxSize = uncompressedSize * 1.001 + 13;
+uLongf compressedSize = maxSize;
+char *compressedBuf = needLargeMem(maxSize);
+int err = compress((Bytef*)compressedBuf, &compressedSize, (Bytef*)uncompressedBuf, uncompressedSize);
+printf("uncompressedSize %d, compressedSize %d, err %d\n", (int)uncompressedSize, (int)compressedSize, err);
+FILE *f = mustOpen(output, "wb");
+mustWrite(f, compressedBuf, compressedSize);
+carefulClose(&f);
+f = mustOpen(uncompressed, "wb");
+uLongf uncSize = uncompressedSize;
+memset(uncompressedBuf, 0, uncompressedSize);
+err = uncompress((Bytef*)uncompressedBuf,  &uncSize, (Bytef*)compressedBuf, compressedSize);
+printf("uncompressedSize %d, err %d\n", (int)uncSize, err);
+mustWrite(f, uncompressedBuf, uncSize);
+carefulClose(&f);
 }
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
-if (argc != 2)
+if (argc != 4)
     usage();
-freen(argv[1]);
+freen(argv[1], argv[2], argv[3]);
 return 0;
 }