home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / BufferStream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  1.8 KB  |  55 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef __BUFFERSTREAM__
  20. #define __BUFFERSTREAM__
  21.  
  22. #include <LFileStream.h>
  23. #include <stddef.h>
  24.  
  25. // Does plain buffered read/writes
  26. // Buffering strategy:
  27. //    reading:    read all you can fit in the buffer
  28. //                give it to the client in small chunks
  29. //    writing:    write all you can fit in the buffer
  30. //                on overflow, flush everything, then write the rest
  31. // for now, we only buffer writing
  32. class LFileBufferStream: public LFileStream
  33. {
  34. public:
  35.                     LFileBufferStream( FSSpec& inFileSpec );
  36.     virtual            ~LFileBufferStream();
  37.     virtual Int32    WriteData( const void *inFromBuffer, Int32 inByteCount );
  38.     virtual Int32    ReadData( void* outToBuffer, Int32 inByteCount );
  39.     virtual    void    CloseDataFork();
  40.     void            DoUseBuffer();
  41.     void            SetURL( char* url ) { fURL = url; }
  42.     char*            GetURL()    { return fURL; }
  43. protected:
  44.     OSErr            FlushBuffer( Boolean allocateNew );
  45.     Boolean            fUseBuffer;
  46.     Handle            fBuffer;
  47.     UInt32            fBufferSize;
  48.     UInt32            fLastWritten;
  49.     Boolean            fWriteFailed;
  50.     char *            fURL;
  51. };
  52.  
  53. #endif // __BUFFERSTREAM__
  54.  
  55.