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

int pbzip2::BZ2StreamScanner::init ( int  hInFile,
size_t  inBuffCapacity = DEFAULT_IN_BUFF_CAPACITY 
)

Initialize - position to beginning of input file and prepare for searching.

Returns:
0 - on success; -1 on error.

Definition at line 41 of file BZ2StreamScanner.cpp.

{
      dispose();

      CharType bz2header[] = "BZh91AY&SY";
      // zero-terminated string
      CharType bz2ZeroHeader[] =
            { 'B', 'Z', 'h', '9', 0x17, 0x72, 0x45, 0x38, 0x50, 0x90, 0 };

      _hInFile = hInFile;
      _eof = false;
      _bz2Header = bz2header;
      _bz2HeaderZero = bz2ZeroHeader;
      _bz2HeaderFound = false;
      _inBuffCapacity = 0;
      _errState = 0;
      _searchStatus = false;
      _outBuffCapacityHint = 0;
      _outBuffCapacityLimit = DEFAULT_OUT_BUFF_LIMIT;
      _outSequenceNumber = 0;
      _streamNumber = 0;

      // Prevent too small buffer
      if ( inBuffCapacity < 2 * _bz2Header.size() )
      {
            inBuffCapacity = 2 * _bz2Header.size();
      }

      // allocate memory to read in file
      _inBuff = new(std::nothrow) CharType[inBuffCapacity];

      if ( _inBuff == NULL )
      {
            _errState |= ERR_MEM_ALLOC_INBUFF;
            _inBuffEnd = NULL;
            handle_error( EF_EXIT, -1,
                        "pbzip2: *ERROR: Could not allocate memory (FileData)!  Aborting...\n" );

            return -1;
      }

      _inBuffCapacity = inBuffCapacity;

      _inBuffCurrent = _inBuffSearchPtr = _inBuffEnd = _inBuff;

      return 0;
}

Generated by  Doxygen 1.6.0   Back to index