//=-- FSGZipped.h - GZ Zipped compressed File Streams ------------------------=
//
// This class allows MagicStats to read from GZipped compressed files.  Please
// note that seeking in these files is an extremely expensive operation.
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-1998 Chris Lattner
//=---------------------------------------------------------------------------=

#ifndef FSGZIPPED_H
#define FSGZIPPED_H

#include "FileStreamPlugin.h"
#include "zlib/zlib.h"
#include <assert.h>

class FSGZipped : public FileStreamPluginImpl<FSGZipped> {
public:

  virtual ~FSGZipped();    // Clean up crew...

  FSGZipped(int &CE) { CE = 1; /* Should never be created without data! */ }
  FSGZipped(const char *Filename, int OpenCode, int &ErrorOccurred);

  // Implement the FileStreamPlugin API
  virtual int seek(long Position, int From = SeekSet);
  virtual long tell();
  virtual FileStreamPlugin *getline(char *Buffer, int BufferLength, char Delimiter = '\n');
  virtual int eof();
  virtual int GetC(char &C);

  inline static unsigned int GetCurrentVersion() {
    return 100;                       // Version 1.00
  }

  inline static const char *GetPluginName() {
    return "GZipped";
  }

  // This has a medium priority, because it is possible to tell via magic 
  // numbers if a file is a GZIP file.
  static int GetPriority() { return 500; }

private :
  gzFile F;
  int EOFFound;
  char Buffer[256];
  char *BufPtr;
  int NumBuffered;
};

#endif
