-------------------------------------------------------------------
+Thu Sep 7 14:32:38 CEST 2006 - mvidner@suse.cz
+
+- Implemented fgzstreambuf::compressed_tell and fXstream::getbuf to
+ enable progress reporting on compressed streams.
+
+-------------------------------------------------------------------
Wed Sep 6 18:31:20 CEST 2006 - dmacvicar@suse.de
- better error propagation
#include "zypp/base/GzStream.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
fgzstreambuf * ret = NULL;
if ( ! isOpen() )
{
+ // we expect gzdopen to handle errors of ::open
if ( mode_r == std::ios_base::in )
- _file = gzopen( name_r, "rb" );
+ {
+ _fd = ::open( name_r, O_RDONLY );
+ _file = gzdopen( _fd, "rb" );
+ }
else if ( mode_r == std::ios_base::out )
- _file = gzopen( name_r, "wb" );
+ {
+ _fd = ::open( name_r, O_WRONLY );
+ _file = gzdopen( _fd, "wb" );
+ }
// else: not supported
if ( isOpen() )
bool failed = false;
if ( sync() != 0 )
failed = true;
+ // it also closes _fd, fine
if ( gzclose( _file ) != Z_OK )
{
failed = true;
}
// Reset everything
+ _fd = -1;
_file = NULL;
_mode = std::ios_base::openmode(0);
setp( NULL, NULL );
return ret;
}
+ fgzstreambuf::pos_type
+ fgzstreambuf::compressed_tell() const
+ {
+ off_t pos = lseek (_fd, 0, SEEK_CUR);
+ // hopefully the conversion is ok
+ return pos;
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace gzstream_detail
///////////////////////////////////////////////////////////////////
public:
fgzstreambuf( unsigned bufferSize_r = 512 )
- : _file( NULL )
+ : _fd( -1 )
+ ,_file( NULL )
, _mode( std::ios_base::openmode(0) )
, _buffer( (bufferSize_r?bufferSize_r:1), 0 )
{}
fgzstreambuf *
close();
+ //! Tell the file position in the compressed file.
+ //! Analogous to tell(2), complementary to gztell.
+ pos_type compressed_tell() const;
+
/**
* The last error returned fron zlib.
**/
typedef std::vector<char> buffer_type;
+ //! file descriptor of the compressed file
+ int _fd;
+
gzFile _file;
std::ios_base::openmode _mode;
zError() const
{ return _streambuf.zError(); }
+ //! Similar to ios::rdbuf.
+ //! But it returns our specific type, not the generic streambuf *.
+ const streambuf_type&
+ getbuf() const
+ { return _streambuf; }
private: