/********************************************************************************
*                                                                               *
*                         B Z S t r e a m   C l a s s e s                       *
*                                                                               *
*********************************************************************************
* Copyright (C) 1999,2003 by Lyle Johnson. All Rights Reserved.                 *
*********************************************************************************
* This library is free software; you can redistribute it and/or                 *
* modify it under the terms of the GNU Lesser General Public                    *
* License as published by the Free Software Foundation; either                  *
* version 2.1 of the License, or (at your option) any later version.            *
*                                                                               *
* This library is distributed in the hope that it will be useful,               *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
* Lesser General Public License for more details.                               *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public              *
* License along with this library; if not, write to the Free Software           *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
*********************************************************************************
* $Id: FXBzStream.h,v 1.8 2003/04/10 20:38:38 fox Exp $                         *
********************************************************************************/
#ifdef HAVE_BZ2LIB_H
#ifndef FXBZSTREAM_H
#define FXBZSTREAM_H

#ifndef FXSTREAM_H
#include "FXStream.h"
#endif


//////////////////////////////  UNDER DEVELOPMENT  //////////////////////////////


namespace FX {


/// BZIP2 compressed file stream
class FXAPI FXBzFileStream : public FXStream {
  void *file;
  void *bzfile;
protected:
  virtual void saveItems(const void *buf,unsigned long n);
  virtual void loadItems(void *buf,unsigned long n);
public:

  /// Create BZIP2 file stream
  FXBzFileStream(const FXObject* cont=NULL);

  /// Open file stream
  FXbool open(const char* filename,FXStreamDirection save_or_load);

  /// Close file stream
  FXbool close();

  /// Move to position
  virtual FXbool position(unsigned long){ return FALSE; }

  /// Clean up
  virtual ~FXBzFileStream();
  };


/// BZIP2 compressed memory stream
class FXAPI FXBzMemoryStream : public FXStream {
private:
  void         *strm;
  unsigned long bzpos;
  FXuchar      *ptr;
  unsigned long space;
  FXbool        owns;
protected:
  virtual void saveItems(const void *buf, unsigned long n);
  virtual void loadItems(void *buf, unsigned long n);
  void finish();
public:

  /// Create memory stream
  FXBzMemoryStream(const FXObject* cont=NULL);

  /// Open store
  FXbool open(FXuchar* data,FXStreamDirection save_or_load);

  /// Open stream with specified size
  FXbool open(FXuchar* data,unsigned long sp,FXStreamDirection save_or_load);

  // Get available space
  unsigned long getSpace() const { return space; }

  /// Set available space
  void setSpace(unsigned long sp);

  /// Take buffer away from stream
  void takeBuffer(FXuchar*& buffer,unsigned long& sp);

  /// Give buffer to stream
  void giveBuffer(FXuchar *buffer,unsigned long sp);

  /// Move to position
  virtual FXbool position(unsigned long) { return FALSE; }

  /// Get final size of compressed stream
  unsigned long getCompressedSize() const { return bzpos; }

  /// Close
  FXbool close();

  /// Destructor
  virtual ~FXBzMemoryStream();
  };

}

#endif
#endif
