MC-NBT is a TypeScript parser and serializer for NBT archives, for use with Node.js.
To install into your project, simply run npm install --save @bedrocker/mc-nbt
in the root of your project.
To read NBT headers from a file, the following code snippet should get you going:
const NBT = require('@bedrocker/mc-nbt')
const fs = require('fs')
fs.readFile('data.nbt', (error, data) => {
if (error) throw error;
nbt.parse(data, (error, data) => {
console.log(data.value.stringTest.value);
console.log(data.value['nested compound test'].value);
});
});
If the file is ZLib compressed, then it will automatically be decompressed first
Returns a buffer with a serialized nbt value. If isLittleEndian is passed and is true, write little endian nbt (mcpe).
Takes a buffer data and returns a parsed nbt value. If isLittleEndian is passed and is true, read little endian nbt (mcpe).
Takes an optionally compressed data and provide a parsed nbt value in the callback(err,value). If isLittleEndian is passed and is true, read little endian nbt (mcpe).
Returns a simplified nbt representation : keep only the value to remove one level. This loses the types so you cannot use the resulting representation to write it back to nbt.
Provide the protodef instance used to parse and serialize nbt.
Provide the protodef instance used to parse and serialize little endian nbt.