Code Monkey home page Code Monkey logo

Comments (5)

winny- avatar winny- commented on July 28, 2024 1

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.

macfreek avatar macfreek commented on July 28, 2024

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.

winny- avatar winny- commented on July 28, 2024

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.

macfreek avatar macfreek commented on July 28, 2024

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.

winny- avatar winny- commented on July 28, 2024

Thank you for the prompt feedback.

If I find time I'd love to contribute improvements. Soon, maybe? 😀

from nbt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.