Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Trimming the fat.

  • Loading branch information...
commit e16414b688bf9ba9e75e37c7aa86907d0d0349ac 1 parent b2640e3
@TkTech authored
Showing with 5 additions and 145 deletions.
  1. +0 −2  pynbt/__init__.py
  2. +0 −31 pynbt/helpers.py
  3. +0 −111 pynbt/region.py
  4. +5 −1 readme.md
View
2  pynbt/__init__.py
@@ -13,5 +13,3 @@
TAG_Compound,
TAG_Int_Array
)
-from pynbt.region import RegionFile
-from pynbt.helpers import is_pocket
View
31 pynbt/helpers.py
@@ -1,31 +0,0 @@
-import gzip
-import struct
-
-def is_pocket(io, compressed=True):
- """
- Returns `False` if the given file `io` is not an (Android) Minecraft
- NBT file.
- """
- fin = open(io, 'rb') if isinstance(io, basestring) else io
- src = gzip.GzipFile(fileobj=fin, mode='rb') if compressed else fin
-
- def read(fmt):
- return struct.unpack(fmt, src.read(struct.calcsize(fmt)))
-
- lead = read('<4b')
-
- if isinstance(io, basestring):
- fin.close()
-
- # The entities.dat header, "ENT\x00".
- if lead == (0x45, 0x4E, 0x54, 0x00):
- # 4 byte magic,
- # 4 byte version?
- # 4 byte file length, minus header.
- return "entities.dat"
- elif lead[0] != 0x0A:
- # 4 byte version?
- # 4 byte file length, minus header.
- return "level.dat"
-
- return False
View
111 pynbt/region.py
@@ -1,111 +0,0 @@
-# -*- coding: utf8 -*-
-"""
-Support for reading Minecraft region files.
-
-This format is simple, albiet with nowhere close to optimal
-performance both in speed or size.
-"""
-import zlib
-import struct
-import os.path
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
-
-from .nbt import NBTFile
-
-
-def chunk_location(l):
- """
- Returns the offset (in bytes) and size (in bytes) of the chuck for
- the given location.
- """
- offset = ((l >> 8) & 0xFF) + ((l >> 16) & 0xFF) + ((l >> 32) & 0xFF)
- size = l & 0xFF
-
- return (offset * 4096, size * 4096)
-
-
-class RegionFile(list):
- def __init__(self, io=None):
- if io is None:
- return
-
- src = open(io, 'rb') if isinstance(io, basestring) else io
-
- def read(fmt):
- return struct.unpack(fmt, src.read(struct.calcsize(fmt)))
-
- t = read('>1024i1024i')
- # The first 1024 integers are the location table entries,
- # and the following 1024 entries are the timestamps.
- chunks = zip(t[:1024], t[1024:])
-
- for location, timestamp in chunks:
- offset, size = chunk_location(location)
- if offset == 0:
- # This chunk hasn't been allocated yet.
- self.append((None, None))
- continue
-
- src.seek(offset)
- length, compression = read('>ib')
-
- if compression == 0:
- # Usually seems to be an improperly erased chunk.
- self.append((None, None))
- continue
- elif compression == 1:
- # gzip'd chunk. This never occurs in practice,
- # but we'll support it anyways.
- buff = StringIO(src.read(length))
- self.append((
- timestamp,
- NBTFile(buff, compressed=True)
- ))
- elif compression == 2:
- # zlib'd chunk. This is the compression scheme actually
- # used in practice.
- buff = StringIO(zlib.decompress(src.read(length)))
- self.append((
- timestamp,
- NBTFile(buff, compressed=False)
- ))
-
- @staticmethod
- def used_chunks(io):
- """
- Returns a list in the form <x, y> of chunks that are used within this
- region file, with <x, y> in chunk coordinates. This exist for quickly
- scanning a region directory for chunks and is much faster than loading
- the entire region file (0.03s vs 3.06s for 40 files).
- """
- fin = open(io, 'rb')
- locs = struct.unpack('>1024i', fin.read(4096))
- fin.close()
-
- rx, ry = os.path.split(io)[1].split('.')[1:3]
- rx, ry = int(rx) << 5, int(ry) << 5
-
- o = []
- for i, l in enumerate(locs):
- if l == 0:
- continue
-
- o.append(
- ((i & 0x1F) + rx, (i >> 5) + ry)
- )
- return o
-
- def pretty(self):
- """
- Returns a formated representation of this region and the chunks
- found within it.
- """
- t = []
- for timestamp, chunk in self:
- if chunk is None:
- continue
- t.append(chunk.pretty())
- return '\n'.join(t)
View
6 readme.md
@@ -1,7 +1,7 @@
# PyNBT
PyNBT is a tiny, liberally licenced (MIT) NBT library.
-It supports reading and writing compressed, uncompressed, big endian or little endian NBT files. It also includes helpers for region files and pocket detection.
+It supports reading and writing compressed, uncompressed, big endian or little endian NBT files.
## Using the Library
Using the library in your own programs is simple and is capable of reading, modifying, and saving NBT files.
@@ -76,6 +76,10 @@ with open('out.nbt') as io:
These changelogs are summaries only and not comprehensive. See
the commit history between tags for full changes.
+### v1.4.0
+- **Removed** pocket detection helpers and ``RegionFile``, leaving PyNBT to **only** handle NBT.
+- Added a simple unicode test.
+
### v1.3.0
- Internal cleanups in ``nbt.py`` to ease some C work.

0 comments on commit e16414b

Please sign in to comment.
Something went wrong with that request. Please try again.