Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Utilities

    NBT 1.3

    Download button

    No screenshots available
    Downloads: 1,704  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Thomas Woolford | More programs
    Other/Proprietary Li... / FREE
    May 22nd, 2012, 01:48 GMT
    ROOT / Utilities

     Read user reviews (0)  Refer to a friend  Subscribe

    NBT description

    Named Binary Tag Reader/Writer

    NBT is a Named Binary Tag parser based upon the specification by Markus Persson.

    From The spec:

     "NBT (Named Binary Tag) is a tag based binary format designed to carry large
     amounts of binary data with smaller amounts of additional data. An NBT file consists of a single GZIPped Named Tag of type TAG_Compound."

    read the full spec at http://www.minecraft.net/docs/NBT.txt

    Usage:

     1. Reading files.

     the easiest way to read an nbt file is to instantiate an NBTFile object e.g.

     >>> import nbt
     >>> nbtfile = nbt.NBTFile("bigtest.nbt",'rb')
     >>> nbtfile.name.value
     u'Level'
     >>> nbtfile["nested compound test"].tag_info()
     TAG_Compound("nested compound test"): 2 Entries
     >>> for tag in nbtfile["nested compound test"]["ham"].tags:
     ... print tag.tag_info()
     ...
     TAG_String("name"): Hampus
     TAG_Float("value"): 0.75
     >>> [tag.value for tag in nbtfile["listTest (long)"].tags]
     [11, 12, 13, 14, 15]


     2. Writing files.

     Writing files is easy too! if you have a NBTFile object, simply call it's write_file() method. If the NBTFile was instantiated with a filename, then write_file needs no extra arguments. It just works. If however you created a new file object from scratch (or even if you just want to save it somewhere else) call write_file('pathtonewfile.nbt')

     >>> import nbt
     >>> nbtfile = nbt.NBTFile("bigtest.nbt",'rb')
     >>> nbtfile["listTest (compound)"][0].value = u'Hello World!'
     >>> nbtfile.write_file("newnbtfile.nbt")


     3. Creating files

     Creating files is trickier but ultimately should give you no issue, as long as you have read the NBT spec (hint.. it's very short). Also be sure to note that the NBTFile object is actually a TAG_Compound with some wrapper features, so you can use all the standard tag features

     >>> from nbt import *
     >>> nbtfile = NBTFile()


     first, don't forget to name the top level tag

     >>> nbtfile.name = TAG_String("My Top Level Tag")
     >>> nbtfile.tags.append(TAG_Float(name="My Float Name", value=3.152987593947))
     >>> mylist = TAG_List(name="TestList", type=TAG_Long) #type needs to be pre-declared!
     >>> mylist.tags.append(TAG_Long(100))
     >>> mylist.tags.extend([TAG_Long(120),TAG_Long(320),TAG_Long(19)])
     >>> nbtfile.tags.append(mylist)
     >>> print nbtfile.pretty_tree()
     TAG_Compound("My Top Level Tag"): 2 Entries
     {
     TAG_Float("My Float Name"): 3.15298759395
     TAG_List("TestList"): 4 entries of type TAG_Long
     {
     TAG_Long: 100
     TAG_Long: 120
     TAG_Long: 320
     TAG_Long: 19
     }
     }
     >>> nbtfile["TestList"].tags.sort(key = lambda tag: tag.value)
     >>> print nbtfile.pretty_tree()
     TAG_Compound("My Top Level Tag"): 2 Entries
     {
     TAG_Float("My FloatName"): 3.15298759395
     TAG_List("TestList"): 4 entries of type TAG_Long
     {
     TAG_Long: 19
     TAG_Long: 100
     TAG_Long: 120
     TAG_Long: 320
     }
     }
     >>> nbtfile.write_file("mynbt.dat")



    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    tag parser | named binary | named | binary | tag

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM