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