2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// GZipFile.h
|
|
|
|
|
|
|
|
// Declares the cGZipFile class representing a RAII wrapper over zlib's GZip file routines
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-11-27 02:40:59 -05:00
|
|
|
#include "zlib/zlib.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cGZipFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum eMode
|
|
|
|
{
|
|
|
|
fmRead, // Read-only. If the file doesn't exist, object will not be valid
|
|
|
|
fmWrite, // Write-only. If the file already exists, it will be overwritten
|
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
cGZipFile(void);
|
|
|
|
~cGZipFile();
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Opens the file. Returns true if successful. Fails if a file has already been opened through this object. */
|
2013-07-29 07:13:03 -04:00
|
|
|
bool Open(const AString & a_FileName, eMode a_Mode);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Closes the file, flushing all buffers. This object may be then reused for a different file and / or mode */
|
2013-07-29 07:13:03 -04:00
|
|
|
void Close(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Reads the rest of the file and decompresses it into a_Contents. Returns the number of decompressed bytes, <0 for error */
|
2013-07-29 07:13:03 -04:00
|
|
|
int ReadRestOfFile(AString & a_Contents);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Writes a_Contents into file, compressing it along the way. Returns true if successful. Multiple writes are supported. */
|
2015-05-24 07:56:56 -04:00
|
|
|
bool Write(const AString & a_Contents) { return Write(a_Contents.data(), static_cast<int>(a_Contents.size())); }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
bool Write(const char * a_Data, int a_Size);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
protected:
|
|
|
|
gzFile m_File;
|
|
|
|
eMode m_Mode;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|