nodejs library for reading and writing NBT files
JavaScript
Switch branches/tags
Nothing to show
Latest commit 03b4ca0 Oct 23, 2016 @djfun djfun committed on GitHub Merge pull request #1 from NurdTurd/patch-1
Make example code prettier.
Permalink
Failed to load latest commit information.
goog first commit Dec 17, 2012
lib first commit Dec 17, 2012
sampledata first commit Dec 17, 2012
test first commit Dec 17, 2012
.gitignore first commit Dec 17, 2012
.travis.yml add travis-ci config Jan 25, 2014
LICENSE first commit Dec 17, 2012
README.md Make example code prettier. Oct 23, 2016
package.json updated readme, updated dependencies, bumped version to 1.0.0 Nov 18, 2014

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