~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to zip/ziptest.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ziptest.cpp : Defines the entry point for the console application.
2
 
//
3
 
 
4
 
#ifndef _WIN32
5
 
#include "../config.h"
6
 
#endif
7
 
#include "boinc_zip.h"
8
 
#include "filesys.h"
9
 
#include <zlib.h>  // CMC -- test that we "co-exist" with the "stock" zlib library
10
 
 
11
 
int do_gzip(const char* strGZ, const char* strInput)
12
 
{
13
 
        // take an input file (strInput) and turn it into a compressed file (strGZ)
14
 
        // get rid of the input file after 
15
 
 
16
 
        FILE* fIn = boinc_fopen(strInput, "rb");
17
 
        if (!fIn)  return 1; //error
18
 
        gzFile fOut = gzopen(strGZ, "wb");
19
 
        if (!fOut) return 1; //error
20
 
 
21
 
        fseek(fIn, 0, SEEK_SET);  // go to the top of the files
22
 
        gzseek(fOut, 0, SEEK_SET);
23
 
        unsigned char buf[1024];
24
 
        long lRead = 0, lWrite = 0;
25
 
        while (!feof(fIn)) { // read 1KB at a time until end of file
26
 
                memset(buf, 0x00, 1024);
27
 
                lRead = 0;
28
 
                lRead = fread(buf, 1, 1024, fIn);
29
 
                lWrite = gzwrite(fOut, buf, lRead);
30
 
                if (lRead != lWrite) break;
31
 
        }
32
 
        gzclose(fOut);
33
 
        fclose(fIn);
34
 
 
35
 
        if (lRead != lWrite) return 1;  //error -- read bytes != written bytes
36
 
 
37
 
        // if we made it here, it compressed OK, can erase strInput and leave
38
 
        boinc_delete_file(strInput);
39
 
        return 0;
40
 
}
41
 
 
42
 
int main(int argc, char* argv[])
43
 
{
44
 
        ZipFileList zflist;
45
 
#ifdef _WIN32
46
 
        boinc_filelist("c:\\temp", "", &zflist, SORT_NAME | SORT_ASCENDING);
47
 
#else
48
 
        boinc_filelist("/tmp/junk", "", &zflist, SORT_NAME | SORT_ASCENDING);
49
 
#endif
50
 
        int jj; 
51
 
                char strTmp[128], strTmp2[128];
52
 
                for (jj = 0; jj < zflist.size(); jj++) {
53
 
                        printf("%s  %d\n", zflist[jj].c_str(), zflist[jj].m_statFile.st_mtime);
54
 
                        // now gzip it, silly but see how it goes!
55
 
                        sprintf(strTmp, "%s.gz", zflist[jj].c_str());
56
 
                        sprintf(strTmp2, "%s.zip", strTmp);
57
 
                     printf("infile=%s  outfile=%s\n", strTmp, strTmp2);
58
 
                        do_gzip(strTmp, zflist[jj].c_str());
59
 
                    boinc_zip(ZIP_IT, strTmp2, strTmp);
60
 
                }
61
 
    boinc_zip(UNZIP_IT, "/tmp/boinc_zip.zip", "/tmp/junk/boinc_zip");
62
 
    return 0;
63
 
}
64
 
 
65
 
const char *BOINC_RCSID_9851414a72 = "$Id: ziptest.cpp 7481 2005-08-25 21:33:28Z davea $";