#include "zypp/base/InputStream.h"
#include "zypp/base/GzStream.h"
+#ifdef ENABLE_ZCHUNK_COMPRESSION
+ #include "zypp/base/ZckStream.h"
+#endif
+
+#include "zypp/PathInfo.h"
+
using std::endl;
///////////////////////////////////////////////////////////////////
{ /////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
+ namespace
+ { /////////////////////////////////////////////////////////////////
+
+ inline std::streamoff _helperInitSize( const Pathname & file_r )
+ {
+ PathInfo p( file_r );
+ if ( p.isFile() && filesystem::zipType( file_r ) == filesystem::ZT_NONE )
+ return p.size();
+ return -1;
+ }
+
+ inline shared_ptr<std::istream> streamForFile ( const Pathname & file_r )
+ {
+ const auto zType = filesystem::zipType( file_r );
+
+#ifdef ENABLE_ZCHUNK_COMPRESSION
+ if ( zType == filesystem::ZT_ZCHNK )
+ return shared_ptr<std::istream>( new ifzckstream( file_r.asString().c_str() ) );
+#endif
+
+ //fall back to gzstream
+ return shared_ptr<std::istream>( new ifgzstream( file_r.asString().c_str() ) );
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
//
// METHOD NAME : InputStream::InputStream
// METHOD TYPE : Constructor
//
InputStream::InputStream( const Pathname & file_r )
: _path( file_r )
- , _stream( new ifgzstream( _path.asString().c_str() ) )
+ , _stream( streamForFile( _path.asString() ) )
, _name( _path.asString() )
+ , _size( _helperInitSize( _path ) )
{}
///////////////////////////////////////////////////////////////////
InputStream::InputStream( const Pathname & file_r,
const std::string & name_r )
: _path( file_r )
- , _stream( new ifgzstream( _path.asString().c_str() ) )
+ , _stream( streamForFile( _path.asString() ) )
, _name( name_r )
+ , _size( _helperInitSize( _path ) )
{}
///////////////////////////////////////////////////////////////////
//
InputStream::InputStream( const std::string & file_r )
: _path( file_r )
- , _stream( new ifgzstream( _path.asString().c_str() ) )
+ , _stream( streamForFile( _path.asString() ) )
, _name( _path.asString() )
+ , _size( _helperInitSize( _path ) )
{}
///////////////////////////////////////////////////////////////////
InputStream::InputStream( const std::string & file_r,
const std::string & name_r )
: _path( file_r )
- , _stream( new ifgzstream( _path.asString().c_str() ) )
+ , _stream( streamForFile( _path.asString() ) )
, _name( name_r )
+ , _size( _helperInitSize( _path ) )
{}
///////////////////////////////////////////////////////////////////
//
InputStream::InputStream( const char * file_r )
: _path( file_r )
- , _stream( new ifgzstream( _path.asString().c_str() ) )
+ , _stream( streamForFile( _path.asString() ) )
, _name( _path.asString() )
+ , _size( _helperInitSize( _path ) )
{}
///////////////////////////////////////////////////////////////////
InputStream::InputStream( const char * file_r,
const std::string & name_r )
: _path( file_r )
- , _stream( new ifgzstream( _path.asString().c_str() ) )
+ , _stream( streamForFile( _path.asString() ) )
, _name( name_r )
+ , _size( _helperInitSize( _path ) )
{}
///////////////////////////////////////////////////////////////////