refactored compressTag and decompressTag so we can use the compressors individually
This commit is contained in:
parent
80f1fd4944
commit
6578ac2aeb
35
mclevel.py
35
mclevel.py
@ -2451,25 +2451,36 @@ class MCInfdevOldLevel(MCLevel):
|
|||||||
else:
|
else:
|
||||||
return MCRegionFile.VERSION_GZIP
|
return MCRegionFile.VERSION_GZIP
|
||||||
|
|
||||||
|
def compressTagGzip(self, root_tag):
|
||||||
|
buf = StringIO.StringIO()
|
||||||
|
with closing(gzip.GzipFile(fileobj=buf, mode='wb', compresslevel=2)) as gzipper:
|
||||||
|
root_tag.save(buf=gzipper)
|
||||||
|
|
||||||
|
return buf.getvalue()
|
||||||
|
|
||||||
|
def compressTagDeflate(self, root_tag):
|
||||||
|
buf = StringIO.StringIO()
|
||||||
|
root_tag.save(buf=buf)
|
||||||
|
return deflate(buf.getvalue())
|
||||||
|
|
||||||
def compressTag(self, root_tag):
|
def compressTag(self, root_tag):
|
||||||
if self.compressMode == MCRegionFile.VERSION_GZIP:
|
if self.compressMode == MCRegionFile.VERSION_GZIP:
|
||||||
buf = StringIO.StringIO()
|
return self.compressTagGzip(root_tag)
|
||||||
with closing(gzip.GzipFile(fileobj=buf, mode='wb', compresslevel=2)) as gzipper:
|
|
||||||
root_tag.save(buf=gzipper)
|
|
||||||
|
|
||||||
return buf.getvalue()
|
|
||||||
|
|
||||||
if self.compressMode == MCRegionFile.VERSION_DEFLATE:
|
if self.compressMode == MCRegionFile.VERSION_DEFLATE:
|
||||||
buf = StringIO.StringIO()
|
return self.compressTagDeflate(root_tag)
|
||||||
root_tag.save(buf=buf)
|
|
||||||
return deflate(buf.getvalue())
|
def decompressTagGzip(self, data):
|
||||||
|
with closing(gzip.GzipFile(fileobj=StringIO.StringIO(data))) as gz:
|
||||||
|
return nbt.load(buf=gz.read())
|
||||||
|
|
||||||
|
def decompressTagDeflate(self, data):
|
||||||
|
return nbt.load(buf=inflate(data))
|
||||||
|
|
||||||
def decompressTag(self, data):
|
def decompressTag(self, data):
|
||||||
if self.compressMode == MCRegionFile.VERSION_GZIP:
|
if self.compressMode == MCRegionFile.VERSION_GZIP:
|
||||||
with closing(gzip.GzipFile(fileobj=StringIO.StringIO(data))) as gz:
|
return self.compressTagGzip(data)
|
||||||
return nbt.load(buf=gz.read())
|
|
||||||
if self.compressMode == MCRegionFile.VERSION_DEFLATE:
|
if self.compressMode == MCRegionFile.VERSION_DEFLATE:
|
||||||
return nbt.load(buf=inflate(data))
|
return self.decompressTagDeflate(data)
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Reference in New Issue
Block a user