refactored compressTag and decompressTag so we can use the compressors individually

This commit is contained in:
David Vierra 2011-04-05 19:59:37 -10:00
parent 80f1fd4944
commit 6578ac2aeb

View File

@ -2451,26 +2451,37 @@ class MCInfdevOldLevel(MCLevel):
else: else:
return MCRegionFile.VERSION_GZIP return MCRegionFile.VERSION_GZIP
def compressTag(self, root_tag): def compressTagGzip(self, root_tag):
if self.compressMode == MCRegionFile.VERSION_GZIP:
buf = StringIO.StringIO() buf = StringIO.StringIO()
with closing(gzip.GzipFile(fileobj=buf, mode='wb', compresslevel=2)) as gzipper: with closing(gzip.GzipFile(fileobj=buf, mode='wb', compresslevel=2)) as gzipper:
root_tag.save(buf=gzipper) root_tag.save(buf=gzipper)
return buf.getvalue() return buf.getvalue()
if self.compressMode == MCRegionFile.VERSION_DEFLATE: def compressTagDeflate(self, root_tag):
buf = StringIO.StringIO() buf = StringIO.StringIO()
root_tag.save(buf=buf) root_tag.save(buf=buf)
return deflate(buf.getvalue()) return deflate(buf.getvalue())
def decompressTag(self, data): def compressTag(self, root_tag):
if self.compressMode == MCRegionFile.VERSION_GZIP: if self.compressMode == MCRegionFile.VERSION_GZIP:
return self.compressTagGzip(root_tag)
if self.compressMode == MCRegionFile.VERSION_DEFLATE:
return self.compressTagDeflate(root_tag)
def decompressTagGzip(self, data):
with closing(gzip.GzipFile(fileobj=StringIO.StringIO(data))) as gz: with closing(gzip.GzipFile(fileobj=StringIO.StringIO(data))) as gz:
return nbt.load(buf=gz.read()) return nbt.load(buf=gz.read())
if self.compressMode == MCRegionFile.VERSION_DEFLATE:
def decompressTagDeflate(self, data):
return nbt.load(buf=inflate(data)) return nbt.load(buf=inflate(data))
def decompressTag(self, data):
if self.compressMode == MCRegionFile.VERSION_GZIP:
return self.compressTagGzip(data)
if self.compressMode == MCRegionFile.VERSION_DEFLATE:
return self.decompressTagDeflate(data)
@property @property
def displayName(self): def displayName(self):