summaryrefslogtreecommitdiffstats
path: root/source/OSSupport/GZipFile.h
blob: bb8a88ec8a6af0b67b7d802ab6e451145665c156 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

// GZipFile.h

// Declares the cGZipFile class representing a RAII wrapper over zlib's GZip file routines





#pragma once

#include "zlib.h"





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
	} ;
	
	cGZipFile(void);
	~cGZipFile();
	
	/// Opens the file. Returns true if successful. Fails if a file has already been opened through this object.
	bool Open(const AString & a_FileName, eMode a_Mode);
	
	/// Closes the file, flushing all buffers. This object may be then reused for a different file and / or mode
	void Close(void);
	
	/// Reads the rest of the file and decompresses it into a_Contents. Returns the number of decompressed bytes, <0 for error
	int ReadRestOfFile(AString & a_Contents);
	
	/// Writes a_Contents into file, compressing it along the way. Returns the number of decompressed bytes, <0 for error. Multiple writes are supported.
	int Write(AString & a_Contents);
	
protected:
	gzFile m_File;
} ;