OSDN Git Service

Support options set by preferences assigned within profile.xml
[mingw/mingw-get.git] / src / pkgstrm.h
1 #ifndef PKGSTRM_H
2 /*
3  * pkgstrm.h
4  *
5  * $Id$
6  *
7  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8  * Copyright (C) 2009, 2010, MinGW Project
9  *
10  *
11  * Declaration of the streaming API, for reading package archives.
12  *
13  *
14  * This is free software.  Permission is granted to copy, modify and
15  * redistribute this software, under the provisions of the GNU General
16  * Public License, Version 3, (or, at your option, any later version),
17  * as published by the Free Software Foundation; see the file COPYING
18  * for licensing details.
19  *
20  * Note, in particular, that this software is provided "as is", in the
21  * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
22  * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
23  * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
24  * MinGW Project, accept liability for any damages, however caused,
25  * arising from the use of this software.
26  *
27  */
28 #define PKGSTRM_H  1
29
30 #include <stdint.h>
31
32 class pkgArchiveStream
33 {
34   /* Abstract base class...
35    * All archive streaming classes are be derived from this.
36    */
37   public:
38     pkgArchiveStream(){}
39     virtual bool IsReady() = 0;
40     virtual int Read( char*, size_t ) = 0;
41     virtual ~pkgArchiveStream(){}
42
43   protected:
44     virtual int GetRawData( int, uint8_t*, size_t );
45 };
46
47 #ifdef PKGSTRM_H_SPECIAL
48 /*
49  * Specialisations of the generic base class...
50  * Most clients don't need to be specifically aware of these;
51  * those that do must #define PKGSTRM_H_SPECIAL, before they
52  * #include pkgstrm.h
53  *
54  */
55 class pkgRawArchiveStream : public pkgArchiveStream
56 {
57   /* A regular (uncompressed) data stream...
58    */
59   protected:
60     int fd;
61
62   public:
63     pkgRawArchiveStream( int );
64     pkgRawArchiveStream( const char* );
65     virtual ~pkgRawArchiveStream();
66
67     inline bool IsReady(){ return fd != -1; }
68     virtual int Read( char*, size_t );
69 };
70
71 /* Compressed data stream classes...
72  */
73 #include <zlib.h>
74 #include <bzlib.h>
75 #include <lzma.h>
76
77 class pkgGzipArchiveStream : public pkgArchiveStream
78 {
79   /* A stream compressed using the "gzip" algorithm...
80    */
81   protected:
82     gzFile stream;
83
84   public:
85     pkgGzipArchiveStream( int );
86     pkgGzipArchiveStream( const char* );
87     virtual ~pkgGzipArchiveStream();
88
89     inline bool IsReady(){ return stream != NULL; }
90     virtual int Read( char*, size_t );
91 };
92
93 class pkgBzipArchiveStream : public pkgArchiveStream
94 {
95   /* A stream compressed using the "bzip2" algorithm...
96    */
97   protected:
98     BZFILE *stream;
99     int bzerror;
100
101   public:
102     pkgBzipArchiveStream( int );
103     pkgBzipArchiveStream( const char* );
104     virtual ~pkgBzipArchiveStream();
105
106     inline bool IsReady(){ return stream != NULL; }
107     virtual int Read( char*, size_t );
108 };
109
110 class pkgLzmaArchiveStream : public pkgArchiveStream
111 {
112   /* A stream compressed using the "lzma" algorithm...
113    */
114   protected:
115     int fd;
116     lzma_stream stream;
117     uint8_t streambuf[BUFSIZ];
118     int status;
119
120   public:
121     pkgLzmaArchiveStream( int );
122     pkgLzmaArchiveStream( const char* );
123     virtual ~pkgLzmaArchiveStream();
124
125     inline bool IsReady(){ return fd != -1; }
126     virtual int Read( char*, size_t );
127 };
128
129 class pkgXzArchiveStream : public pkgArchiveStream
130 {
131   /* A stream compressed using the "xz" algorithm...
132    */
133   protected:
134     int fd;
135     lzma_stream stream;
136     uint8_t streambuf[BUFSIZ];
137     lzma_action opmode;
138     int status;
139
140   public:
141     pkgXzArchiveStream( int );
142     pkgXzArchiveStream( const char* );
143     virtual ~pkgXzArchiveStream();
144
145     inline bool IsReady(){ return fd != -1; }
146     virtual int Read( char*, size_t );
147 };
148
149 #endif /* PKGSTRM_H_SPECIAL */
150
151 /* A generic helper function, to open an archive stream using
152  * the appropriate specialised stream class...
153  */
154 extern "C" pkgArchiveStream *pkgOpenArchiveStream( const char* );
155
156 #endif /* PKGSTRM_H: $RCSfile$: end of file */