@@ -525,27 +525,21 @@ g3_istream_close(std::istream &stream)
525525class OutputStreamCounter : public std ::streambuf {
526526public:
527527 OutputStreamCounter (std::streambuf* buffer)
528- : bytes_( 0 ), buffer_(buffer ) {
528+ : buffer_(buffer ), bytes_( 0 ) {
529529 if (!buffer_)
530530 log_fatal (" Input file stream buffer required" );
531531 }
532532
533- OutputStreamCounter () : bytes_(0 ), buffer_(nullptr ) {}
534-
535- std::streampos bytes () const { return bytes_; }
536-
537533protected:
538- virtual int_type overflow (int_type c) {
539- if (buffer_ && buffer_ ->sputc (c) != traits_type::eof ()) {
534+ int_type overflow (int_type c) {
535+ if (buffer_->sputc (c) != traits_type::eof ()) {
540536 bytes_++;
541537 return c;
542538 }
543539 return traits_type::eof ();
544540 }
545541
546- virtual std::streamsize xsputn (const char * s, std::streamsize n) {
547- if (!buffer_)
548- return 0 ;
542+ std::streamsize xsputn (const char * s, std::streamsize n) {
549543 std::streamsize nput = buffer_->sputn (s, n);
550544 if (nput > 0 )
551545 bytes_ += nput;
@@ -564,17 +558,16 @@ class OutputStreamCounter : public std::streambuf {
564558 log_fatal (" Seek not implemented for output stream" );
565559 }
566560
567- size_t bytes_;
568-
569561private:
570562 std::streambuf* buffer_;
563+ size_t bytes_;
571564};
572565
573566template <typename T, typename C>
574- class Encoder : public OutputStreamCounter {
567+ class Encoder : public std ::streambuf {
575568public:
576569 Encoder (std::ostream &file, size_t size)
577- : file_(file), inbuf_(size), outbuf_(size) {}
570+ : file_(file), inbuf_(size), outbuf_(size), bytes_( 0 ) {}
578571
579572protected:
580573 int_type overflow (int_type c) {
@@ -622,9 +615,22 @@ class Encoder : public OutputStreamCounter {
622615
623616 virtual int encode (bool flush) = 0;
624617
618+ std::streampos seekoff (std::streamoff off, std::ios_base::seekdir way,
619+ std::ios_base::openmode mode) {
620+ // short-circuit for tellp
621+ if ((mode & std::ios_base::out) && off == 0 && way == std::ios_base::cur)
622+ return bytes_;
623+ log_fatal (" Seek not implemented for compressed stream" );
624+ }
625+
626+ std::streampos seekpos (std::streampos pos, std::ios_base::openmode mode) {
627+ log_fatal (" Seek not implemented for compressed stream" );
628+ }
629+
625630 std::ostream &file_;
626631 std::vector<char > inbuf_;
627632 std::vector<char > outbuf_;
633+ size_t bytes_;
628634 T stream_;
629635};
630636
0 commit comments