text: 
  // ***** filestream.h *****
  
  class BBFileStream : public BBStream{
  public:
  
  	BBFileStream();
  	~BBFileStream();
  
  	void Close();
  	int Eof();
  	int Length();
  	int Position();
  	int Seek( int position );
  	int Read( BBDataBuffer *buffer,int offset,int count );
  	int Write( BBDataBuffer *buffer,int offset,int count );
  
  	bool Open( String path,String mode );
  	
  private:
  	FILE *_file;
  	int _position;
  	int _length;
  };
  
  // ***** filestream.cpp *****
  
  BBFileStream::BBFileStream():_file(0),_position(0),_length(0){
  }
  
  BBFileStream::~BBFileStream(){
  	if( _file ) fclose( _file );
  }
  
  bool BBFileStream::Open( String path,String mode ){
  	if( _file ) return false;
  
  	String fmode;	
  	if( mode=="r" ){
  		fmode="rb";
  	}else if( mode=="w" ){
  		fmode="wb";
  	}else if( mode=="u" ){
  		fmode="rb+";
  	}else{
  		return false;
  	}
  
  	_file=BBGame::Game()->OpenFile( path,fmode );
  	if( !_file && mode=="u" ) _file=BBGame::Game()->OpenFile( path,"wb+" );
  	if( !_file ) return false;
  	
  	fseek( _file,0,SEEK_END );
  	_length=ftell( _file );
  	fseek( _file,0,SEEK_SET );
  	_position=0;
  	
  	return true;
  }
  
  void BBFileStream::Close(){
  	if( !_file ) return;
  	
  	fclose( _file );
  	_file=0;
  	_position=0;
  	_length=0;
  }
  
  int BBFileStream::Eof(){
  	if( !_file ) return -1;
  	
  	return _position==_length;
  }
  
  int BBFileStream::Length(){
  	return _length;
  }
  
  int BBFileStream::Position(){
  	return _position;
  }
  
  int BBFileStream::Seek( int position ){
  	if( !_file ) return 0;
  	
  	fseek( _file,position,SEEK_SET );
  	_position=ftell( _file );
  	return _position;
  }
  
  int BBFileStream::Read( BBDataBuffer *buffer,int offset,int count ){
  	if( !_file ) return 0;
  	
  	int n=fread( buffer->WritePointer(offset),1,count,_file );
  	_position+=n;
  	return n;
  }
  
  int BBFileStream::Write( BBDataBuffer *buffer,int offset,int count ){
  	if( !_file ) return 0;
  	
  	int n=fwrite( buffer->ReadPointer(offset),1,count,_file );
  	_position+=n;
  	if( _position>_length ) _length=_position;
  	return n;
  }
  