libzypp  17.23.6
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 #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
zypp::InputStream::~InputStream
~InputStream()
Dtor.
Definition: InputStream.cc:158
shared_ptr
PathInfo.h
GzStream.h
zypp::ifgzstream
detail::fXstream< std::istream, gzstream_detail::fgzstreambuf > ifgzstream
istream reading gzip files as well as plain files.
Definition: GzStream.h:157
zypp::filesystem::ZT_NONE
Definition: PathInfo.h:778
zypp::filesystem::ZT_ZCHNK
Definition: PathInfo.h:778
ZckStream.h
LogTools.h
zypp::InputStream
Helper to create and pass std::istream.
Definition: InputStream.h:56
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::InputStream::stream
std::istream & stream() const
The std::istream.
Definition: InputStream.h:93
zypp::ifzckstream
detail::fXstream< std::istream, detail::ZChunkStreamBuf > ifzckstream
istream reading zchunk files.
Definition: ZckStream.h:69
zypp::asString
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
Definition: DefaultIntegral.h:98
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
zypp::filesystem::zipType
ZIP_TYPE zipType(const Pathname &file)
Definition: PathInfo.cc:1072
std
Definition: Arch.h:347
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
InputStream.h
str
String related utilities and Regular expression matching.
zypp::InputStream::name
const std::string & name() const
Name of the std::istream.
Definition: InputStream.h:107
zypp::NullDeleter
shared_ptr custom deleter doing nothing.
Definition: PtrTypes.h:82
zypp::InputStream::InputStream
InputStream()
Default ctor providing std::cin.
Definition: InputStream.cc:62