diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-02-07 11:09:42 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-02-07 11:09:42 +0100 |
commit | ed47a8e409ac8d5273a3d6b61aba90248cc4c70d (patch) | |
tree | dc98dfc9bebd34b4746bd4ae83812eb24aef763f /source/OSSupport | |
parent | Added a sanity check to cBlockArea:Crop() (diff) | |
download | cuberite-ed47a8e409ac8d5273a3d6b61aba90248cc4c70d.tar cuberite-ed47a8e409ac8d5273a3d6b61aba90248cc4c70d.tar.gz cuberite-ed47a8e409ac8d5273a3d6b61aba90248cc4c70d.tar.bz2 cuberite-ed47a8e409ac8d5273a3d6b61aba90248cc4c70d.tar.lz cuberite-ed47a8e409ac8d5273a3d6b61aba90248cc4c70d.tar.xz cuberite-ed47a8e409ac8d5273a3d6b61aba90248cc4c70d.tar.zst cuberite-ed47a8e409ac8d5273a3d6b61aba90248cc4c70d.zip |
Diffstat (limited to 'source/OSSupport')
-rw-r--r-- | source/OSSupport/GZipFile.cpp | 28 | ||||
-rw-r--r-- | source/OSSupport/GZipFile.h | 5 |
2 files changed, 31 insertions, 2 deletions
diff --git a/source/OSSupport/GZipFile.cpp b/source/OSSupport/GZipFile.cpp index 8f5edd3d7..dbdef3a8b 100644 --- a/source/OSSupport/GZipFile.cpp +++ b/source/OSSupport/GZipFile.cpp @@ -36,6 +36,7 @@ bool cGZipFile::Open(const AString & a_FileName, eMode a_Mode) return false;
}
m_File = gzopen(a_FileName.c_str(), (a_Mode == fmRead) ? "r" : "w");
+ m_Mode = a_Mode;
return (m_File != NULL);
}
@@ -64,6 +65,12 @@ int cGZipFile::ReadRestOfFile(AString & a_Contents) return -1;
}
+ if (m_Mode != fmRead)
+ {
+ ASSERT(!"Bad file mode, cannot read");
+ 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];
@@ -77,3 +84,24 @@ int cGZipFile::ReadRestOfFile(AString & a_Contents) +
+bool cGZipFile::Write(const AString & a_Contents)
+{
+ if (m_File == NULL)
+ {
+ ASSERT(!"No file has been opened");
+ return false;
+ }
+
+ if (m_Mode != fmWrite)
+ {
+ ASSERT(!"Bad file mode, cannot write");
+ return false;
+ }
+
+ return (gzwrite(m_File, a_Contents.data(), a_Contents.size()) != 0);
+}
+
+
+
+
diff --git a/source/OSSupport/GZipFile.h b/source/OSSupport/GZipFile.h index bb8a88ec8..10fb447dd 100644 --- a/source/OSSupport/GZipFile.h +++ b/source/OSSupport/GZipFile.h @@ -36,11 +36,12 @@ public: /// 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);
+ /// Writes a_Contents into file, compressing it along the way. Returns true if successful. Multiple writes are supported.
+ bool Write(const AString & a_Contents);
protected:
gzFile m_File;
+ eMode m_Mode;
} ;
|