Logo Search packages:      
Sourcecode: pbzip2 version File versions  Download package

outBuff * pbzip2::BZ2StreamScanner::getNextStream (  )

Get next BZ2 stream from the input.

Returns:
output buffer initialized with bz2 stream. failure() should be checked after calling this method - true would mean failure(). If failure() is false:
  • outBuff.bufSize == 0 indicates end of file;

Definition at line 569 of file BZ2StreamScanner.cpp.

{
      initOutBuff();

      #ifdef PBZIP_DEBUG
      static OFF_T blockNum = 0;
      #endif

      outBuff * res = new(std::nothrow) outBuff;
      if ( res == NULL )
      {
            handle_error( EF_EXIT, -1,
                  "pbzip2: *ERROR: Could not allocate memory (getNextStream/%u)!"
                  "Aborting...\n", (unsigned) sizeof( outBuff ) );

            _errState |= ERR_MEM_ALLOC_OUTBUFF;
            return res;
      }

      res->buf = NULL;
      res->bufSize = std::numeric_limits<unsigned int>::max();

      // first search
      if ( !failed() && !isBz2HeaderFound() )
      {
            #ifdef PBZIP_DEBUG
            blockNum = 0;
            fprintf( stderr, " First search start\n" );
            #endif

            _searchStatus = false;
            searchNextHeader();
      }

      if ( failed() )
      {
            return res;
      }

      if ( ( getInBuffCurrent() == getInBuffEnd() ) && eof() )
      {
            // end of file
            #ifdef PBZIP_DEBUG
            fprintf( stderr, " End of file\n" );
            #endif

            res->bufSize = 0;
            return res;
      }
      
      if ( ( getInBuffCurrent() == getInBuffSearchPtr() ) ||
            ( !getSearchStatus() && !eof() ) )
      {
            // search for next header
            // Slide a bit to skip current header in order to search for next one.
            _inBuffSearchPtr = std::min( getInBuffSearchPtr() + _bz2Header.size(),
                                                 getInBuffEnd() );
            _searchStatus = false;

            #ifdef PBZIP_DEBUG
            fprintf( stderr, " getNextStream - Searching subsequent header... " );
            printCurrentState();
            fprintf( stderr, "\n" );
            #endif
            
            searchNextHeader();
      }

      if ( failed() )
      {
            return res;
      }

      appendOutBuffDataUpToLimit();

      if ( failed() )
      {
            return res;
      }

      if ( _outSequenceNumber > 0 )
      {
            // continuing an unterminated sequence
            ++_outSequenceNumber;
      }
      else if ( getInBuffCurrent() != getInBuffSearchPtr() )
      {
            // start of long multi-part stream
            _outSequenceNumber = 1;
      }
      
      _outBuff.sequenceNumber = _outSequenceNumber;
      _outBuff.inSize = _outBuff.bufSize;
      _outBuff.blockNumber = _streamNumber;

      if ( getInBuffCurrent() == getInBuffSearchPtr() )
      {
            // we're at end of stream (either single or multi-segment one)
            _outBuff.isLastInSequence = true;
            _outSequenceNumber = 0;
            ++_streamNumber;
      }
      else
      {
            _outBuff.isLastInSequence = false;
      }


      #ifdef PBZIP_DEBUG
      OFF_T startBlock = blockNum;
      blockNum += _outBuff.bufSize;

      fprintf( stderr, " end getNextStream/blockRange=[%"PRIu64", %"PRIu64"), stream no=%d; seq=%d: [",
             startBlock, blockNum, _outBuff.blockNumber, _outBuff.sequenceNumber );
      printCurrentState();
      fprintf( stderr, "\n" );
      #endif

      *res = _outBuff;
      // clean-up pointers to returned data.
      initOutBuff();

      return res;
}

Generated by  Doxygen 1.6.0   Back to index