Changes between Version 11 and Version 12 of FileCompression


Ignore:
Timestamp:
Nov 22, 2010, 9:31:51 PM (14 years ago)
Author:
carlgt1
Comment:

added some boinc_zip updates, new svn location, gzip stuff

Legend:

Unmodified
Added
Removed
Modified
  • FileCompression

    v11 v12  
    133133boinc_zip, based on the [http://www.info-zip.org Info-Zip] libraries, but combines both zip & unzip
    134134functionality in one library.
    135 Any questions/comments please email Carl Christensen.
     135Any questions/comments please email Carl Christensen  mailto:carlgt1@yahoo.com]
    136136
    137137This library can "co-exist" with zlib (libz) in case you need that too.
     
    219219with how `boinc_zip` work (just g++ with the `boinc/lib/filesys.C` & `util.C` as
    220220described above).
     221
     222=== Getting boinc_zip ===
     223
     224boinc_zip is no longer in the main boinc subversion "trunk" but resides in this "depends" brance:
     225
     226svn co http://boinc.berkeley.edu/svn/trunk/depends_projects/zip
     227
     228Note for Linux/Mac:  To build along with the other boinc libraries, you will need to add the following lines to the bottom of the '''configure.ac''' file (where the various Makefiles are listed):
     229
     230{{{
     231     zip/Makefile
     232     zip/zip/Makefile
     233     zip/unzip/Makefile
     234}}}
     235
     236
     237Similarly for the '''Makefile.am''' file -- add zip, zip/zip and zip/unzip to the library subdirs:
     238
     239{{{
     240if ENABLE_LIBRARIES
     241   API_SUBDIRS = api lib zip zip/zip zip/unzip
     242endif
     243}}}
     244
     245== Client and Server Compression and Decompression using gzip (zlib) == #gzip
     246
     247These basic routines may be useful if you want to compress/decompress a file using the zlib library (usually called "libz.a" and available for most platforms).  Include the header file below (qcn_gzip.h) in your program, and link against libz, and you will gain two simple to use functions for gzip'ing or gunzip'ing a file.  This is for simple single file or file-by-file compression or decompression (i.e. one file that is to be compressed into a .gz or decompressed back to it's original uncompressed state).  You can check for boinc client status if you want the ability to quit inside an operation etc.
     248
     249qcn_gzip.h:
     250
     251{{{
     252#ifndef _QCN_GZIP_H_
     253#define _QCN_GZIP_H_
     254
     255#include <zlib.h>
     256
     257int do_gzip(const char* strGZ, const char* strInput);
     258int do_gunzip(const char* strGZ, const char* strInput, bool bKeep = false);
     259
     260#endif
     261}}}
     262
     263
     264qcn_gzip.cpp:
     265
     266{{{
     267#include <stdio.h>
     268#include "filesys.h"
     269#include "qcn_gzip.h"
     270
     271int do_gzip(const char* strGZ, const char* strInput)
     272{
     273        // take an input file (strInput) and turn it into a compressed file (strGZ)
     274        // get rid of the input file after
     275        FILE* fIn = boinc_fopen(strInput, "rb");
     276        if (!fIn)  return 1; //error
     277        gzFile fOut = gzopen(strGZ, "wb");
     278        if (!fOut) return 1; //error
     279        fseek(fIn, 0, SEEK_SET);  // go to the top of the files
     280        gzseek(fOut, 0, SEEK_SET);
     281        unsigned char buf[1024];
     282        long lRead = 0, lWrite = 0;
     283        while (!feof(fIn)) { // read 1KB at a time until end of file
     284                memset(buf, 0x00, 1024);
     285                lRead = 0;
     286                lRead = (long) fread(buf, 1, 1024, fIn);
     287                lWrite = (long) gzwrite(fOut, buf, lRead);
     288                if (lRead != lWrite) break;
     289        }
     290        gzclose(fOut);
     291        fclose(fIn);
     292        if (lRead != lWrite) return 1;  //error -- read bytes != written bytes
     293        // if we made it here, it compressed OK, can erase strInput and leave
     294        boinc_delete_file(strInput);
     295        return 0;
     296}
     297
     298// CMC - commented out status calls, are they too paranoid?
     299//      if needed use sm->statusBOINC instead (for quit_request etc)
     300
     301int do_gunzip(const char* strGZ, const char* strInput, bool bKeep)
     302{
     303        // take an input file (strInput) and turn it into a compressed file (strGZ)
     304        // get rid of the input file after
     305        //s.quit_request = 0;
     306        //checkBOINCStatus();
     307        FILE* fIn = boinc_fopen(strInput, "wb");
     308        if (!fIn)  return 1; //error
     309        gzFile fOut = gzopen(strGZ, "rb");
     310        if (!fOut) return 1; //error
     311        fseek(fIn, 0, SEEK_SET);  // go to the top of the files
     312        gzseek(fOut, 0, SEEK_SET);
     313        unsigned char buf[1024];
     314        long lRead = 0, lWrite = 0;
     315        while (!gzeof(fOut)) { // read 1KB at a time until end of file
     316                memset(buf, 0x00, 1024);
     317                lRead = 0;
     318                lRead = (long) gzread(fOut,buf,1024);
     319                lWrite = (long) fwrite(buf, 1, 1024, fIn);
     320                if (lRead != lWrite) break;
     321                //boinc_get_status(&s);
     322                //if (s.quit_request || s.abort_request || s.no_heartbeat) break;
     323        }
     324        gzclose(fOut);
     325        fclose(fIn);
     326        //checkBOINCStatus();
     327        if (lRead != lWrite) return 1;  //error -- read bytes != written bytes
     328        // if we made it here, it compressed OK, can erase strInput and leave
     329        if (!bKeep) boinc_delete_file(strGZ);
     330        return 0;
     331}
     332
     333}}}