libzypp 17.31.0
inputstream.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <zypp-core/base/LogTools.h>
14
15#include "inputstream.h"
16#include <zypp-core/base/GzStream>
17
18#ifdef ENABLE_ZCHUNK_COMPRESSION
19 #include <zypp-core/base/ZckStream>
20#endif
21
22#include <zypp-core/fs/PathInfo.h>
23
24using std::endl;
25
27namespace zypp
28{
29
31 namespace
32 {
33
34 inline std::streamoff _helperInitSize( const Pathname & file_r )
35 {
36 PathInfo p( file_r );
37 if ( p.isFile() && filesystem::zipType( file_r ) == filesystem::ZT_NONE )
38 return p.size();
39 return -1;
40 }
41
42 inline shared_ptr<std::istream> streamForFile ( const Pathname & file_r )
43 {
44#ifdef ENABLE_ZCHUNK_COMPRESSION
45 if ( const auto zType = filesystem::zipType( file_r ); zType == filesystem::ZT_ZCHNK )
46 return shared_ptr<std::istream>( new ifzckstream( file_r.asString().c_str() ) );
47#endif
48
49 //fall back to gzstream
50 return shared_ptr<std::istream>( new ifgzstream( file_r.asString().c_str() ) );
51 }
52
54 } // namespace
56
58 //
59 // METHOD NAME : InputStream::InputStream
60 // METHOD TYPE : Constructor
61 //
63 : _stream( &std::cin, NullDeleter() )
64 , _name( "STDIN" )
65 {}
66
68 //
69 // METHOD NAME : InputStream::InputStream
70 // METHOD TYPE : Constructor
71 //
72 InputStream::InputStream( std::istream & stream_r,
73 const std::string & name_r )
74 : _stream( &stream_r, NullDeleter() )
75 , _name( name_r )
76 {}
77
79 //
80 // METHOD NAME : InputStream::InputStream
81 // METHOD TYPE : Constructor
82 //
84 : _path( file_r )
85 , _stream( streamForFile( _path.asString() ) )
86 , _name( _path.asString() )
87 , _size( _helperInitSize( _path ) )
88 {}
89
91 //
92 // METHOD NAME : InputStream::InputStream
93 // METHOD TYPE : Constructor
94 //
96 const std::string & name_r )
97 : _path( file_r )
98 , _stream( streamForFile( _path.asString() ) )
99 , _name( name_r )
100 , _size( _helperInitSize( _path ) )
101 {}
102
104 //
105 // METHOD NAME : InputStream::InputStream
106 // METHOD TYPE : Constructor
107 //
108 InputStream::InputStream( const std::string & file_r )
109 : _path( file_r )
110 , _stream( streamForFile( _path.asString() ) )
111 , _name( _path.asString() )
112 , _size( _helperInitSize( _path ) )
113 {}
114
116 //
117 // METHOD NAME : InputStream::InputStream
118 // METHOD TYPE : Constructor
119 //
120 InputStream::InputStream( const std::string & file_r,
121 const std::string & name_r )
122 : _path( file_r )
123 , _stream( streamForFile( _path.asString() ) )
124 , _name( name_r )
125 , _size( _helperInitSize( _path ) )
126 {}
127
129 //
130 // METHOD NAME : InputStream::InputStream
131 // METHOD TYPE : Constructor
132 //
133 InputStream::InputStream( const char * file_r )
134 : _path( file_r )
135 , _stream( streamForFile( _path.asString() ) )
136 , _name( _path.asString() )
137 , _size( _helperInitSize( _path ) )
138 {}
139
141 //
142 // METHOD NAME : InputStream::InputStream
143 // METHOD TYPE : Constructor
144 //
145 InputStream::InputStream( const char * file_r,
146 const std::string & name_r )
147 : _path( file_r )
148 , _stream( streamForFile( _path.asString() ) )
149 , _name( name_r )
150 , _size( _helperInitSize( _path ) )
151 {}
152
154 //
155 // METHOD NAME : InputStream::~InputStream
156 // METHOD TYPE : Destructor
157 //
159 {}
160
161 /******************************************************************
162 **
163 ** FUNCTION NAME : operator<<
164 ** FUNCTION TYPE : std::ostream &
165 */
166 std::ostream & operator<<( std::ostream & str, const InputStream & obj )
167 {
168 return str << obj.name() << obj.stream();
169 }
170
172} // namespace zypp
Helper to create and pass std::istream.
Definition: inputstream.h:57
const std::string & name() const
Name of the std::istream.
Definition: inputstream.h:107
std::istream & stream() const
The std::istream.
Definition: inputstream.h:93
InputStream()
Default ctor providing std::cin.
Definition: inputstream.cc:62
Definition: Arch.h:352
String related utilities and Regular expression matching.
ZIP_TYPE zipType(const Pathname &file)
Definition: PathInfo.cc:1124
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
detail::fXstream< std::istream, detail::ZChunkStreamBuf > ifzckstream
istream reading zchunk files.
Definition: zckstream.h:69
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122
detail::fXstream< std::istream, gzstream_detail::fgzstreambuf > ifgzstream
istream reading gzip files as well as plain files.
Definition: gzstream.h:157
shared_ptr custom deleter doing nothing.
Definition: PtrTypes.h:83