nodejs library for reading and writing NBT files for Minecraft
Easy via npm: npm install node-nbt
.
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.
- 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
- 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.
- TAG.END
- TAG.BYTE
- TAG.SHORT
- TAG.INT
- TAG.LONG
- TAG.FLOAT
- TAG.DOUBLE
- TAG.BYTEARRAY
- TAG.STRING
- TAG.LIST
- TAG.COMPOUND
- TAG.INTARRAY
node-nbt is used in production by mc-map-item-tool
In the test
folder there are some unit tests that can be run with nodeunit.
node-nbt is licensed under the MIT License