Comments (5)
Oops, I finally noticed one may pass a file-like object to the constructor as keyword argument buffer
.
Maybe there should instead be a keyword argument gzipped
that defaults to True?
from nbt.
Glad you found the solution!
I'm not a big fan of the current API. In this case, I would rather see a separate classes GzippedNBTFile
and UncompressedNBTFile
. Preferably with factory methods instead of alternatives in __init__
.
E.g.
GzippedNBTFile(UncompressedNBTFile):
def __init__(self):
...
@staticmethod
def from_fileobject(self, fileobj):
...
@staticmethod
def from_filename(self, filename):
...
Also, I rather saw that NBTFile has a TAG_Compound, instead that it is a TAG_Compound.
However, these changes were never made, since we liked to retain backward compatibility, and introducing another method to accomplish the same would likely be confusing to most users.
What would you consider a good API?
from nbt.
That is one approach, though I think the path of least resistance might be adding a gzipped
keyword argument that defaults to True, and mark the buffer
keyword argument as deprecated (but keep it for backward compatibility) since it assumes the file is not compressed.
Additionally, it is possible to detect if a file is gzipped: https://gist.github.com/winny-/6043044#file-mc_change_spawn-py-L50-L56 — so perhaps auto-detection could be implemented.
from nbt.
Auto-detection is certainly nice, though not very Pythonic (from import this
: In the face of ambiguity, refuse the temptation to guess.).
Point about an easier API is taken. Code contributions are, as always, welcome. I may have a look later, but this has low priority for me.
PS: the reason I prefer a distinct RawNBTFile
and GZipNBTFile
class, instead of a single NBTFile
class with a plethora of __init__
parameters is that it is more scalable: I wouldn't be surprised if at some point, a zlib-compressed NBT File sees the light of day (that is the default compression in region files), and in that case the number of __init__
parameters would grow a bit too big.
from nbt.
Thank you for the prompt feedback.
If I find time I'd love to contribute improvements. Soon, maybe?
from nbt.
Related Issues (20)
- Proble: TypeError: string indices must be integers HOT 1
- NBT does not use UTF-8, it's MUTF-8. HOT 10
- README should show `nbt.nbt.NBTFile()` for usage instead of `nbt.NBTFile()` HOT 1
- Compound tags never named HOT 1
- How do you delete an NBT entry?
- A way to port to newer Minecraft versions? HOT 1
- get_region should limit the number of open files
- ImportError in Python 3.10: cannot import name 'MutableMapping' from 'collections' HOT 9
- [Question, Potential Bug Report]: _render_buffer recursion when trying to modify region files in entities folder HOT 1
- [Question] How to get block data from blockstates
- (Question) Trying to modify region binary to replace stuff in minecraft world using blockdata
- KeyError: Tag Level does not exist when using Minecraft 1.18.1 worlds. HOT 3
- Can someone add support for 1.18 world height. Chunk section range should support -4 to 19, not 0 to 15. Thanks!
- Error while creating data: "struct.error: int too large to convert" HOT 1
- Unable to set value for Compound HOT 1
- Writing a compound tag to a file HOT 1
- 'TAG_End' is not defined HOT 3
- Using the map example with a 1.8 world renders nothing but black. HOT 2
- Can't save .mca HOT 2
- Get uncompressed NBT data to variable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbt.