~inkscape.dev/inkscape/trunk

« back to all changes in this revision

Viewing changes to src/io/gzipstream.h

  • Committer: mental
  • Date: 2006-01-16 02:36:01 UTC
  • Revision ID: mental@users.sourceforge.net-20060116023601-wkr0h7edl5veyudq
moving trunk for module inkscape

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __INKSCAPE_IO_GZIPSTREAM_H__
 
2
#define __INKSCAPE_IO_GZIPSTREAM_H__
 
3
/**
 
4
 * Zlib-enabled input and output streams
 
5
 *
 
6
 * This is a thin wrapper of libz calls, in order
 
7
 * to provide a simple interface to our developers
 
8
 * for gzip input and output.
 
9
 *
 
10
 * Authors:
 
11
 *   Bob Jamison <rjamison@titan.com>
 
12
 *
 
13
 * Copyright (C) 2004 Inkscape.org
 
14
 *
 
15
 * Released under GNU GPL, read the file 'COPYING' for more information
 
16
 */
 
17
 
 
18
 
 
19
#include "inkscapestream.h"
 
20
#include <zlib.h>
 
21
 
 
22
namespace Inkscape
 
23
{
 
24
namespace IO
 
25
{
 
26
 
 
27
//#########################################################################
 
28
//# G Z I P    I N P U T    S T R E A M
 
29
//#########################################################################
 
30
 
 
31
/**
 
32
 * This class is for deflating a gzip-compressed InputStream source
 
33
 *
 
34
 */
 
35
class GzipInputStream : public BasicInputStream
 
36
{
 
37
 
 
38
public:
 
39
 
 
40
    GzipInputStream(InputStream &sourceStream);
 
41
    
 
42
    virtual ~GzipInputStream();
 
43
    
 
44
    virtual int available();
 
45
    
 
46
    virtual void close();
 
47
    
 
48
    virtual int get();
 
49
    
 
50
private:
 
51
 
 
52
    bool load();
 
53
    int fetchMore();
 
54
 
 
55
    bool loaded;
 
56
    
 
57
    long totalIn;
 
58
    long totalOut;
 
59
 
 
60
    unsigned char *outputBuf;
 
61
    unsigned char *srcBuf;
 
62
 
 
63
    unsigned long crc;
 
64
    unsigned long srcCrc;
 
65
    unsigned long srcSiz;
 
66
    unsigned long srcConsumed;
 
67
    unsigned long srcLen;
 
68
    long outputBufPos;
 
69
    long outputBufLen;
 
70
 
 
71
    z_stream d_stream;
 
72
}; // class GzipInputStream
 
73
 
 
74
 
 
75
 
 
76
 
 
77
//#########################################################################
 
78
//# G Z I P    O U T P U T    S T R E A M
 
79
//#########################################################################
 
80
 
 
81
/**
 
82
 * This class is for gzip-compressing data going to the
 
83
 * destination OutputStream
 
84
 *
 
85
 */
 
86
class GzipOutputStream : public BasicOutputStream
 
87
{
 
88
 
 
89
public:
 
90
 
 
91
    GzipOutputStream(OutputStream &destinationStream);
 
92
    
 
93
    virtual ~GzipOutputStream();
 
94
    
 
95
    virtual void close();
 
96
    
 
97
    virtual void flush();
 
98
    
 
99
    virtual void put(int ch);
 
100
 
 
101
private:
 
102
 
 
103
    std::vector<unsigned char> inputBuf;
 
104
 
 
105
    long totalIn;
 
106
    long totalOut;
 
107
    unsigned long crc;
 
108
 
 
109
}; // class GzipOutputStream
 
110
 
 
111
 
 
112
 
 
113
 
 
114
 
 
115
 
 
116
 
 
117
} // namespace IO
 
118
} // namespace Inkscape
 
119
 
 
120
 
 
121
#endif /* __INKSCAPE_IO_GZIPSTREAM_H__ */