From e0535ca6dfee3e5680d591e5764529596d4d412d Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 7 Feb 2013 09:15:55 +0000 Subject: Added a cGZipFile class for reading GZipped files. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1196 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/BlockArea.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'source/BlockArea.cpp') diff --git a/source/BlockArea.cpp b/source/BlockArea.cpp index cdabf0378..6a973efe6 100644 --- a/source/BlockArea.cpp +++ b/source/BlockArea.cpp @@ -7,7 +7,7 @@ #include "Globals.h" #include "BlockArea.h" #include "World.h" -#include "zlib.h" +#include "OSSupport/GZipFile.h" #include "WorldStorage/FastNBT.h" @@ -194,28 +194,21 @@ bool cBlockArea::LoadFromSchematicFile(const AString & a_FileName) { // Un-GZip the contents: AString Contents; - gzFile File = gzopen(a_FileName.c_str(), "rb"); - if (File == NULL) + cGZipFile File; + if (!File.Open(a_FileName, cGZipFile::fmRead)) { LOG("Cannot open the schematic file \"%s\".", a_FileName.c_str()); return false; } - // Since the gzip format doesn't really support getting the uncompressed length, we need to read incrementally. Yuck! - int NumBytesRead = 0; - char Buffer[32 KiB]; - while ((NumBytesRead = gzread(File, Buffer, sizeof(Buffer))) > 0) - { - Contents.append(Buffer, NumBytesRead); - } + int NumBytesRead = File.ReadRestOfFile(Contents); if (NumBytesRead < 0) { LOG("Cannot read GZipped data in the schematic file \"%s\", error %d", a_FileName.c_str(), NumBytesRead); - gzclose(File); return false; } - gzclose(File); + File.Close(); - // TODO: Parse the NBT: + // Parse the NBT: cParsedNBT NBT(Contents.data(), Contents.size()); if (!NBT.IsValid()) { -- cgit v1.2.3