Skip to content

Instantly share code, notes, and snippets.

@lifthrasiir
Created March 10, 2013 14:24
Show Gist options
  • Save lifthrasiir/5128763 to your computer and use it in GitHub Desktop.
Save lifthrasiir/5128763 to your computer and use it in GitHub Desktop.
def run(limit=None):
import os, array, struct, time, zlib
if limit is None: limit = time.time() - 3*3600
for i in os.listdir('.'):
if not i.endswith('.mca'): continue
_,ccx,ccz,_ = i.split('.')
ccx = int(ccx) * 32; ccz = int(ccz) * 32
with open(i, 'rb') as f:
offsets = array.array('I', f.read(4096)); offsets.byteswap()
timestamps = array.array('I', f.read(4096)); timestamps.byteswap()
chunks = [(ts, (i, off/256*4096, off%256*4096), (ccx+j%32, ccz+j/32)) for j, (off, ts) in enumerate(zip(offsets, timestamps)) if off != 0 and ts >= limit]
for ts, (fn, off, sz), (cx, cz) in chunks:
f.seek(off)
data = f.read(sz)
datalen = struct.unpack('!I', data[:4])[0]
datact = ord(data[4])
assert datact == 2, datact
data = zlib.decompress(data[5:4+datalen])
print len(data)
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment