nodejs library for reading and writing NBT files
Switch branches/tags
Nothing to show
Clone or download
djfun Merge pull request #1 from NurdTurd/patch-1
Make example code prettier.
Latest commit 03b4ca0 Oct 23, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
goog
lib
sampledata
test
.gitignore
.travis.yml
LICENSE
README.md
package.json

README.md

node-nbt Build Status

nodejs library for reading and writing NBT files for Minecraft

How to install

Easy via npm: npm install node-nbt.

How to use

Here is a simple example how you can read a gzipped NBT file into a Javascript object.

var NbtReader = require('node-nbt').NbtReader;

var fs = require('fs');
fs.readFile('a_nbt_file.dat', function(err, data) {
  zlib.gunzip(data, function(err, buffer) {
    if (!err) {
      var d = NbtReader.readTag(buffer);
      d = NbtReader.removeBufferKey(d);
    } else {
      console.log(err);
    }
  });
});

If you want to print that Javascript object to the console you can use the NbtReader.printAscii(d); function.

Available methods

NbtReader

  • readTag: reads a tag of any type from a raw buffer
  • readTagName: determines the type of the buffer by reading the tag name
  • readString
  • readShort
  • readInt
  • readLong
  • readFloat
  • readDouble
  • readByte
  • readByteArray
  • readIntArray
  • removeBufferKey: removes the raw buffer with nbt data from the javascript object
  • printAscii: prints the analyzed nbt javascript object to the console

NbtWriter

  • writeTag: writes a tag of any type to a buffer
  • writeTagName
  • writeString
  • writeShort
  • writeInt
  • writeLong
  • writeFloat
  • writeDouble
  • writeByte
  • writeByteArray
  • writeIntArray

If you are writing user input to NBT consider using try-catch to catch TypeErrors.

Available Types

  • TAG.END
  • TAG.BYTE
  • TAG.SHORT
  • TAG.INT
  • TAG.LONG
  • TAG.FLOAT
  • TAG.DOUBLE
  • TAG.BYTEARRAY
  • TAG.STRING
  • TAG.LIST
  • TAG.COMPOUND
  • TAG.INTARRAY

Example

node-nbt is used in production by mc-map-item-tool

Tests

In the test folder there are some unit tests that can be run with nodeunit.

License

node-nbt is licensed under the MIT License