libzypp 17.31.1
gzstream.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| |
3| __ __ ____ _____ ____ |
4| \ \ / /_ _/ ___|_ _|___ \ |
5| \ V / _` \___ \ | | __) | |
6| | | (_| |___) || | / __/ |
7| |_|\__,_|____/ |_| |_____| |
8| |
9| core system |
10| (C) SuSE Linux Products GmbH |
11\----------------------------------------------------------------------/
12
13 File: GzStream.h
14
15 Author: Michael Andres <ma@suse.de>
16 Maintainer: Michael Andres <ma@suse.de>
17
18 Purpose: Streams reading and writing gzip files.
19
20/-*/
21#ifndef ZYPP_CORE_BASE_GZSTREAM_H
22#define ZYPP_CORE_BASE_GZSTREAM_H
23
24#include <iosfwd>
25#include <streambuf>
26#include <vector>
27#include <zlib.h>
28
29#include <zypp-core/base/SimpleStreambuf>
30#include <zypp-core/base/fXstream>
31
33namespace zypp
34{
35
37 namespace gzstream_detail
38 {
39
41 //
42 // CLASS NAME : ZlibError
46 struct ZlibError
47 {
52
56 int _errno;
57
59 : _zError( 0 ), _errno( 0 )
60 {}
61
65 std::string
66 strerror() const;
67 };
69
71 inline std::ostream & operator<<( std::ostream & str, const ZlibError & obj )
72 { return str << obj.strerror(); }
73
74
76 //
77 // CLASS NAME : gzstreambufimpl
91 public:
92
94
96 { closeImpl(); }
97
98 bool
99 isOpen () const
100 { return _file; }
101
102 bool
103 canRead () const
104 { return( _mode == std::ios_base::in ); }
105
106 bool
107 canWrite () const
108 { return( _mode == std::ios_base::out ); }
109
110 bool
111 canSeek ( std::ios_base::seekdir way_r ) const
112 { return ( way_r == std::ios_base::beg || way_r == std::ios_base::cur ); }
113
114 protected:
115 bool openImpl( const char * name_r, std::ios_base::openmode mode_r );
116 bool closeImpl ();
117
120 off_t compressed_tell() const;
121
122 public:
127 error() const
128 { return _error; }
129
130 std::streamsize readData ( char * buffer_r, std::streamsize maxcount_r );
131 bool writeData( const char * buffer_r, std::streamsize count_r );
132 off_t seekTo( off_t off_r, std::ios_base::seekdir way_r, std::ios_base::openmode omode_r );
133 off_t tell() const;
134
135 private:
136
137 void
138 setZError() const
139 { gzerror( _file, &_error._zError ); }
140
142 int _fd = -1;
143
144 gzFile _file = nullptr;
145
146 std::ios_base::openmode _mode = std::ios_base::openmode(0);
147
149
150 };
152 } // namespace gzstream_detail
153
158
163
165} // namespace zypp
167
168#endif // ZYPP_CORE_BASE_GZSTREAM_H
Common template to define ifgzstream/ofgzstream reading/writing compressed files.
Definition: fxstream.h:27
Streambuffer reading or writing gzip files.
Definition: gzstream.h:90
bool canSeek(std::ios_base::seekdir way_r) const
Definition: gzstream.h:111
bool writeData(const char *buffer_r, std::streamsize count_r)
Definition: gzstream.cc:157
off_t seekTo(off_t off_r, std::ios_base::seekdir way_r, std::ios_base::openmode omode_r)
Definition: gzstream.cc:174
error_type error() const
The last error returned fron zlib.
Definition: gzstream.h:127
int _fd
file descriptor of the compressed file
Definition: gzstream.h:142
bool openImpl(const char *name_r, std::ios_base::openmode mode_r)
Definition: gzstream.cc:74
off_t compressed_tell() const
Tell the file position in the compressed file.
Definition: gzstream.cc:197
std::streamsize readData(char *buffer_r, std::streamsize maxcount_r)
Definition: gzstream.cc:143
std::ios_base::openmode _mode
Definition: gzstream.h:146
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
detail::fXstream< std::ostream, gzstream_detail::fgzstreambuf > ofgzstream
ostream writing gzip files.
Definition: gzstream.h:162
detail::fXstream< std::istream, gzstream_detail::fgzstreambuf > ifgzstream
istream reading gzip files as well as plain files.
Definition: gzstream.h:157
Helper class to ship zlib errors.
Definition: gzstream.h:47
std::ostream & operator<<(std::ostream &str, const ZlibError &obj)
Stream output.
Definition: gzstream.h:71
int _errno
errno, valid if zError is Z_ERRNO
Definition: gzstream.h:56
int _zError
The zlib error code.
Definition: gzstream.h:51
std::string strerror() const
Return string describing the zlib error code.
Definition: gzstream.cc:54