libzypp  17.22.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/base/LogTools.h"
14 
15 #include "zypp/base/InputStream.h"
16 #include "zypp/base/GzStream.h"
17 
18 #ifdef ENABLE_ZCHUNK_COMPRESSION
19  #include "zypp/base/ZckStream.h"
20 #endif
21 
22 #include "zypp/PathInfo.h"
23 
24 using std::endl;
25 
27 namespace 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  const auto zType = filesystem::zipType( file_r );
45 
46 #ifdef ENABLE_ZCHUNK_COMPRESSION
47  if ( zType == filesystem::ZT_ZCHNK )
48  return shared_ptr<std::istream>( new ifzckstream( file_r.asString().c_str() ) );
49 #endif
50 
51  //fall back to gzstream
52  return shared_ptr<std::istream>( new ifgzstream( file_r.asString().c_str() ) );
53  }
54 
56  } // namespace
58 
60  //
61  // METHOD NAME : InputStream::InputStream
62  // METHOD TYPE : Constructor
63  //
65  : _stream( &std::cin, NullDeleter() )
66  , _name( "STDIN" )
67  {}
68 
70  //
71  // METHOD NAME : InputStream::InputStream
72  // METHOD TYPE : Constructor
73  //
74  InputStream::InputStream( std::istream & stream_r,
75  const std::string & name_r )
76  : _stream( &stream_r, NullDeleter() )
77  , _name( name_r )
78  {}
79 
81  //
82  // METHOD NAME : InputStream::InputStream
83  // METHOD TYPE : Constructor
84  //
86  : _path( file_r )
87  , _stream( streamForFile( _path.asString() ) )
88  , _name( _path.asString() )
89  , _size( _helperInitSize( _path ) )
90  {}
91 
93  //
94  // METHOD NAME : InputStream::InputStream
95  // METHOD TYPE : Constructor
96  //
98  const std::string & name_r )
99  : _path( file_r )
100  , _stream( streamForFile( _path.asString() ) )
101  , _name( name_r )
102  , _size( _helperInitSize( _path ) )
103  {}
104 
106  //
107  // METHOD NAME : InputStream::InputStream
108  // METHOD TYPE : Constructor
109  //
110  InputStream::InputStream( const std::string & file_r )
111  : _path( file_r )
112  , _stream( streamForFile( _path.asString() ) )
113  , _name( _path.asString() )
114  , _size( _helperInitSize( _path ) )
115  {}
116 
118  //
119  // METHOD NAME : InputStream::InputStream
120  // METHOD TYPE : Constructor
121  //
122  InputStream::InputStream( const std::string & file_r,
123  const std::string & name_r )
124  : _path( file_r )
125  , _stream( streamForFile( _path.asString() ) )
126  , _name( name_r )
127  , _size( _helperInitSize( _path ) )
128  {}
129 
131  //
132  // METHOD NAME : InputStream::InputStream
133  // METHOD TYPE : Constructor
134  //
135  InputStream::InputStream( const char * file_r )
136  : _path( file_r )
137  , _stream( streamForFile( _path.asString() ) )
138  , _name( _path.asString() )
139  , _size( _helperInitSize( _path ) )
140  {}
141 
143  //
144  // METHOD NAME : InputStream::InputStream
145  // METHOD TYPE : Constructor
146  //
147  InputStream::InputStream( const char * file_r,
148  const std::string & name_r )
149  : _path( file_r )
150  , _stream( streamForFile( _path.asString() ) )
151  , _name( name_r )
152  , _size( _helperInitSize( _path ) )
153  {}
154 
156  //
157  // METHOD NAME : InputStream::~InputStream
158  // METHOD TYPE : Destructor
159  //
161  {}
162 
163  /******************************************************************
164  **
165  ** FUNCTION NAME : operator<<
166  ** FUNCTION TYPE : std::ostream &
167  */
168  std::ostream & operator<<( std::ostream & str, const InputStream & obj )
169  {
170  return str << obj.name() << obj.stream();
171  }
172 
174 } // namespace zypp
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
detail::fXstream< std::istream, gzstream_detail::fgzstreambuf > ifgzstream
istream reading gzip files as well as plain files.
Definition: GzStream.h:157
String related utilities and Regular expression matching.
Definition: Arch.h:347
Helper to create and pass std::istream.
Definition: InputStream.h:56
ZIP_TYPE zipType(const Pathname &file)
Definition: PathInfo.cc:1077
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
const std::string & name() const
Name of the std::istream.
Definition: InputStream.h:107
InputStream()
Default ctor providing std::cin.
Definition: InputStream.cc:64
shared_ptr custom deleter doing nothing.
Definition: PtrTypes.h:82
std::istream & stream() const
The std::istream.
Definition: InputStream.h:93
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
detail::fXstream< std::istream, detail::ZChunkStreamBuf > ifzckstream
istream reading zchunk files.
Definition: ZckStream.h:69