summaryrefslogtreecommitdiffstats
path: root/source/OSSupport/GZipFile.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-02-07 10:15:55 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-02-07 10:15:55 +0100
commite0535ca6dfee3e5680d591e5764529596d4d412d (patch)
tree1cbbc76193f67b9f78c52149afeddaccaf791256 /source/OSSupport/GZipFile.cpp
parentcBlockArea can now be loaded from a .schematic file. (diff)
downloadcuberite-e0535ca6dfee3e5680d591e5764529596d4d412d.tar
cuberite-e0535ca6dfee3e5680d591e5764529596d4d412d.tar.gz
cuberite-e0535ca6dfee3e5680d591e5764529596d4d412d.tar.bz2
cuberite-e0535ca6dfee3e5680d591e5764529596d4d412d.tar.lz
cuberite-e0535ca6dfee3e5680d591e5764529596d4d412d.tar.xz
cuberite-e0535ca6dfee3e5680d591e5764529596d4d412d.tar.zst
cuberite-e0535ca6dfee3e5680d591e5764529596d4d412d.zip
Diffstat (limited to '')
-rw-r--r--source/OSSupport/GZipFile.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/source/OSSupport/GZipFile.cpp b/source/OSSupport/GZipFile.cpp
new file mode 100644
index 000000000..8f5edd3d7
--- /dev/null
+++ b/source/OSSupport/GZipFile.cpp
@@ -0,0 +1,79 @@
+
+// GZipFile.cpp
+
+// Implements the cGZipFile class representing a RAII wrapper over zlib's GZip file routines
+
+#include "Globals.h"
+#include "GZipFile.h"
+
+
+
+
+
+cGZipFile::cGZipFile(void) :
+ m_File(NULL)
+{
+}
+
+
+
+
+
+cGZipFile::~cGZipFile()
+{
+ Close();
+}
+
+
+
+
+
+bool cGZipFile::Open(const AString & a_FileName, eMode a_Mode)
+{
+ if (m_File != NULL)
+ {
+ ASSERT(!"A file is already open in this object");
+ return false;
+ }
+ m_File = gzopen(a_FileName.c_str(), (a_Mode == fmRead) ? "r" : "w");
+ return (m_File != NULL);
+}
+
+
+
+
+
+void cGZipFile::Close(void)
+{
+ if (m_File != NULL)
+ {
+ gzclose(m_File);
+ m_File = NULL;
+ }
+}
+
+
+
+
+
+int cGZipFile::ReadRestOfFile(AString & a_Contents)
+{
+ if (m_File == NULL)
+ {
+ ASSERT(!"No file has been opened");
+ return -1;
+ }
+
+ // Since the gzip format doesn't really support getting the uncompressed length, we need to read incrementally. Yuck!
+ int NumBytesRead = 0;
+ char Buffer[64 KiB];
+ while ((NumBytesRead = gzread(m_File, Buffer, sizeof(Buffer))) > 0)
+ {
+ a_Contents.append(Buffer, NumBytesRead);
+ }
+ return NumBytesRead;
+}
+
+
+
+