Socket
Socket
Sign inDemoInstall

prismarine-nbt

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prismarine-nbt

A parser and serializer for NBT archives


Version published
Maintainers
3
Created
Source

Prismarine-NBT

NPM version Build Status

Prismarine-NBT is a JavaScript parser and serializer for NBT archives, for use with Node.js. It supports big, little, and little-varint encoded NBT files.

Usage

as a async promise
const fs = require('fs')
const { parse, writeUncompressed } = require('prismarine-nbt')

async function main(file) {
    const buffer = await fs.promises.readFile(file)
    const { parsed, type } = await parse(buffer)
    const json = JSON.stringify(result, null, 2)
    console.log('JSON serialized:', json)

    // Write it back 
    const outBuffer = fs.createWriteStream('file.nbt')
    const newBuf = writeUncompressed(result, type)
    outBuffer.write(newBuf)
    outBuffer.end(() => console.log('written!'))
}

main(process.argv[2])
as a callback
var fs = require('fs'),
    nbt = require('prismarine-nbt');

fs.readFile('bigtest.nbt', function(error, data) {
    if (error) throw error;

    nbt.parse(data, function(error, data) {
        console.log(data.value.stringTest.value);
        console.log(data.value['nested compound test'].value);
    });
});

If the data is gzipped, it is automatically decompressed, for the buffer see metadata.buffer

API

parse(data, [format]): Promise<{ parsed, type, metadata: { size, buffer? } }>

parse(data, [format,] callback)

Takes an optionally compressed data buffer and reads the nbt data.

If the endian format is known, it can be specified as 'big', 'little' or 'littleVarint'. If not specified, the library will try to sequentially load as big, little and little varint until the parse is successful. The deduced type is returned as type.

Minecraft Java Edition uses big-endian format, and Bedrock uses little-endian.

writeUncompressed(value, format='big')

Returns a buffer with a serialized nbt value.

parseUncompressed(data, format='big')

Takes a buffer data and returns a parsed nbt value.

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.

protos : { big, little, littleVarint }

Provides compiled protodef instances used to parse and serialize nbt

proto

Provide the big-endian protodef instance used to parse and serialize nbt.

protoLE

Provide the little-endian protodef instance used to parse and serialize little endian nbt.

builder

Provides a way to build complex nbt structures simply:

const nbt = require('prismarine-nbt')
writePlayerNbt({
  Air: nbt.short(300),
  Armor: nbt.list(
    nbt.comp({ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") }),
    nbt.comp({ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") }),
    nbt.comp({ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string("") }),
  ),
})

Keywords

FAQs

Package last updated on 06 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc