@bedrocker/mc-nbt
v0.1.15
Published
A named binary tag parser specifically for Minecraft files, with built-in ZLib de-compression.
Downloads
17
Maintainers
Readme
Minecraft NBT Parser
Built with TypeScript
MC-NBT is a TypeScript parser and serializer for NBT archives, for use with Node.js.
Installation
To install into your project, simply run npm install --save @bedrocker/mc-nbt
in the root of your project.
Usage
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
API
writeUncompressed(value,[isLittleEndian])
Returns a buffer with a serialized nbt value. If isLittleEndian is passed and is true, write little endian nbt (mcpe).
parseUncompressed(data,[isLittleEndian])
Takes a buffer data and returns a parsed nbt value. If isLittleEndian is passed and is true, read little endian nbt (mcpe).
parse(data,[isLittleEndian], callback)
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).
simplify(nbt)
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.
proto
Provide the protodef instance used to parse and serialize nbt.
protoLE
Provide the protodef instance used to parse and serialize little endian nbt.