1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/InputStream.cc
13 #include "zypp/base/LogTools.h"
15 #include "zypp/base/InputStream.h"
16 #include "zypp/base/GzStream.h"
18 #ifdef ENABLE_ZCHUNK_COMPRESSION
19 #include "zypp/base/ZckStream.h"
22 #include "zypp/PathInfo.h"
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
34 inline std::streamoff _helperInitSize( const Pathname & file_r )
37 if ( p.isFile() && filesystem::zipType( file_r ) == filesystem::ZT_NONE )
42 inline shared_ptr<std::istream> streamForFile ( const Pathname & file_r )
44 const auto zType = filesystem::zipType( file_r );
46 #ifdef ENABLE_ZCHUNK_COMPRESSION
47 if ( zType == filesystem::ZT_ZCHNK )
48 return shared_ptr<std::istream>( new ifzckstream( file_r.asString().c_str() ) );
51 //fall back to gzstream
52 return shared_ptr<std::istream>( new ifgzstream( file_r.asString().c_str() ) );
55 /////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////
61 // METHOD NAME : InputStream::InputStream
62 // METHOD TYPE : Constructor
64 InputStream::InputStream()
65 : _stream( &std::cin, NullDeleter() )
69 ///////////////////////////////////////////////////////////////////
71 // METHOD NAME : InputStream::InputStream
72 // METHOD TYPE : Constructor
74 InputStream::InputStream( std::istream & stream_r,
75 const std::string & name_r )
76 : _stream( &stream_r, NullDeleter() )
80 ///////////////////////////////////////////////////////////////////
82 // METHOD NAME : InputStream::InputStream
83 // METHOD TYPE : Constructor
85 InputStream::InputStream( const Pathname & file_r )
87 , _stream( streamForFile( _path.asString() ) )
88 , _name( _path.asString() )
89 , _size( _helperInitSize( _path ) )
92 ///////////////////////////////////////////////////////////////////
94 // METHOD NAME : InputStream::InputStream
95 // METHOD TYPE : Constructor
97 InputStream::InputStream( const Pathname & file_r,
98 const std::string & name_r )
100 , _stream( streamForFile( _path.asString() ) )
102 , _size( _helperInitSize( _path ) )
105 ///////////////////////////////////////////////////////////////////
107 // METHOD NAME : InputStream::InputStream
108 // METHOD TYPE : Constructor
110 InputStream::InputStream( const std::string & file_r )
112 , _stream( streamForFile( _path.asString() ) )
113 , _name( _path.asString() )
114 , _size( _helperInitSize( _path ) )
117 ///////////////////////////////////////////////////////////////////
119 // METHOD NAME : InputStream::InputStream
120 // METHOD TYPE : Constructor
122 InputStream::InputStream( const std::string & file_r,
123 const std::string & name_r )
125 , _stream( streamForFile( _path.asString() ) )
127 , _size( _helperInitSize( _path ) )
130 ///////////////////////////////////////////////////////////////////
132 // METHOD NAME : InputStream::InputStream
133 // METHOD TYPE : Constructor
135 InputStream::InputStream( const char * file_r )
137 , _stream( streamForFile( _path.asString() ) )
138 , _name( _path.asString() )
139 , _size( _helperInitSize( _path ) )
142 ///////////////////////////////////////////////////////////////////
144 // METHOD NAME : InputStream::InputStream
145 // METHOD TYPE : Constructor
147 InputStream::InputStream( const char * file_r,
148 const std::string & name_r )
150 , _stream( streamForFile( _path.asString() ) )
152 , _size( _helperInitSize( _path ) )
155 ///////////////////////////////////////////////////////////////////
157 // METHOD NAME : InputStream::~InputStream
158 // METHOD TYPE : Destructor
160 InputStream::~InputStream()
163 /******************************************************************
165 ** FUNCTION NAME : operator<<
166 ** FUNCTION TYPE : std::ostream &
168 std::ostream & operator<<( std::ostream & str, const InputStream & obj )
170 return str << obj.name() << obj.stream();
173 /////////////////////////////////////////////////////////////////
175 ///////////////////////////////////////////////////////////////////