### Browser Bundle with Browserify
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Provides instructions for creating a browser-compatible bundle of Prismarine-NBT using Browserify. This allows the library to be used in web applications. The example also shows how to fetch an NBT file in the browser and parse it.
```bash
npx browserify -r prismarine-nbt -o pnbt.js
```
```html
```
--------------------------------
### Browser Usage with Browserify/Webpack
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Fetch and parse NBT files in the browser using `fetch` and `ArrayBuffer`. This example demonstrates parsing an NBT file and also building and serializing NBT data entirely within the browser environment.
```html
```
--------------------------------
### Build Complex NBT Structures
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Illustrates how to construct complex NBT data structures using the builder API. This is useful for programmatically creating NBT data before serialization. The example shows creating a compound tag with nested lists and other primitive types.
```javascript
const nbt = require('prismarine-nbt')
const tag = nbt.comp({
Air: nbt.short(300),
Armor: nbt.list(nbt.comp([
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('a') },
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('b') },
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('c') }
]))
})
nbt.writeUncompressed(tag) // now do something with this nbt buffer...
```
--------------------------------
### Prismarine-NBT TagType Enum Usage
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Demonstrates how to use the TagType enum for identifying NBT tag types and for type-safe dispatch in TypeScript. Ensure prismarine-nbt is installed.
```javascript
const { TagType } = require('prismarine-nbt')
console.log(TagType.Byte) // 'byte'
console.log(TagType.Short) // 'short'
console.log(TagType.Int) // 'int'
console.log(TagType.Long) // 'long'
console.log(TagType.Float) // 'float'
console.log(TagType.Double) // 'double'
console.log(TagType.String) // 'string'
console.log(TagType.List) // 'list'
console.log(TagType.Compound) // 'compound'
console.log(TagType.ByteArray) // 'byteArray'
console.log(TagType.ShortArray) // 'shortArray'
console.log(TagType.IntArray) // 'intArray'
console.log(TagType.LongArray) // 'longArray'
// Use in type-safe dispatch
function describeTag (tag) {
switch (tag.type) {
case TagType.Compound: return `compound with keys: ${Object.keys(tag.value).join(', ')}`
case TagType.List: return `list<${tag.value.type}> of length ${tag.value.value.length}`
case TagType.String: return `string: "${tag.value}"`
default: return `${tag.type}: ${tag.value}`
}
}
const nbt = require('prismarine-nbt')
console.log(describeTag(nbt.comp({ x: nbt.int(1) })))
// => 'compound with keys: x'
console.log(describeTag(nbt.list(nbt.comp([{ a: nbt.byte(1) }]))))
// => 'list of length 1'
console.log(describeTag(nbt.string('hello')))
// => 'string: "hello"'
```
--------------------------------
### Prismarine-NBT Raw ProtoDef Protocol Access
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Shows how to access and use pre-compiled ProtoDef protocol instances for direct low-level NBT packet manipulation. Requires prismarine-nbt.
```javascript
const nbt = require('prismarine-nbt')
// Direct protocol access for advanced use
const bigProto = nbt.proto // big-endian ProtoDef instance
const littleProto = nbt.protoLE // little-endian ProtoDef instance
const varintProto = nbt.protos.littleVarint
// Parse raw buffer directly via ProtoDef
const buf = nbt.writeUncompressed(nbt.comp({ n: nbt.int(42) }))
const parsed = bigProto.parsePacketBuffer('nbt', buf)
console.log(parsed.data.value.n.value) // 42
console.log(parsed.metadata.size) // byte count consumed
// Serialize via ProtoDef directly
const tag = { type: 'compound', name: '', value: { n: { type: 'int', value: 99 } } }
const rawBuf = bigProto.createPacketBuffer('nbt', tag)
console.log(rawBuf.length) // e.g. 14
// All three protos
console.log(Object.keys(nbt.protos)) // ['big', 'little', 'littleVarint']
```
--------------------------------
### Parse and Write NBT Data (Async)
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Demonstrates asynchronous parsing of an NBT file using promises, simplifying the parsed data, and writing it back to a new file. Requires fs module for file operations.
```javascript
const fs = require('fs')
const nbt = require('prismarine-nbt')
async function main(file) {
const buffer = fs.readFileSync(file)
const { parsed, type } = await nbt.parse(buffer)
console.log('As JSON', JSON.stringify(parsed))
console.log('Simplified', nbt.simplify(parsed))
// Write it back
fs.createWriteStream('bigtest.nbt')
.write(nbt.writeUncompressed(parsed, type))
}
main('bigtest.nbt')
```
--------------------------------
### builder
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Provides a utility for constructing complex NBT structures in a simplified manner.
```APIDOC
## builder
Provides a way to build complex nbt structures simply:
```js
const nbt = require('prismarine-nbt')
const tag = nbt.comp({
Air: nbt.short(300),
Armor: nbt.list(nbt.comp([
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('a') },
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('b') },
{ Count: nbt.byte(0), Damage: nbt.short(0), Name: nbt.string('c') }
]))
})
nbt.writeUncompressed(tag) // now do something with this nbt buffer...
```
See [index.d.ts](typings/index.d.ts#L69) for methods
```
--------------------------------
### Integrating NBT Types with ProtoDef Compiler
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Demonstrates registering prismarine-nbt types into an external ProtoDef Compiler instance for embedding NBT fields within larger schemas. Requires 'protodef' and 'prismarine-nbt'.
```javascript
const { ProtoDefCompiler } = require('protodef').Compiler
const nbt = require('prismarine-nbt')
// Extend a custom ProtoDef compiler with NBT types
const compiler = new ProtoDefCompiler()
nbt.addTypesToCompiler('big', compiler) // add big-endian NBT types
// Now add your own application-level types that reference NBT
compiler.addTypesToCompile({
playerPacket: ['container', [
{ name: 'entityId', type: 'i32' },
{ name: 'nbtData', type: 'nbt' } // reference the registered 'nbt' type
]]
})
const proto = compiler.compileProtoDefSync()
// Serialize a playerPacket containing an inline NBT compound
const packet = {
entityId: 12345,
nbtData: {
type: 'compound',
name: 'Data',
value: {
Health: { type: 'float', value: 20.0 },
Name: { type: 'string', value: 'Alex' }
}
}
}
const buf = proto.createPacketBuffer('playerPacket', packet)
console.log('packet bytes:', buf.length)
const decoded = proto.parsePacketBuffer('playerPacket', buf)
console.log(decoded.data.entityId) // 12345
console.log(decoded.data.nbtData.value.Name.value) // 'Alex'
```
--------------------------------
### Constructing NBT Tags with Builder Functions
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Use factory functions like `byte()`, `string()`, `comp()`, `list()`, etc., to create typed NBT tag objects. These builders compose naturally for building complex NBT structures.
```javascript
const fs = require('fs')
const nbt = require('prismarine-nbt')
// Full entity NBT structure using builder API
const entityTag = nbt.comp({
// Primitive types
id: nbt.string('minecraft:creeper'),
Health: nbt.float(20.0),
MaxHealth: nbt.float(20.0),
Age: nbt.short(0),
FuseTime: nbt.int(30),
Powered: nbt.byte(0), // 0 = not charged
ExplosionRadius: nbt.byte(3),
// Long value as [high32, low32]
UUIDMost: nbt.long([294, 1379390861]),
UUIDLeast: nbt.long([0, -123456789]),
// Nested compound
Motion: nbt.comp({
x: nbt.double(0.0),
y: nbt.double(-0.0784),
z: nbt.double(0.0)
}),
// List of compounds
Armor: nbt.list(nbt.comp([
{ id: nbt.string('minecraft:iron_helmet'), Count: nbt.byte(1), Slot: nbt.byte(103) },
{ id: nbt.string('minecraft:iron_chestplate'), Count: nbt.byte(1), Slot: nbt.byte(102) }
])),
// Array types
Tags: nbt.list({ type: 'string', value: ['hostile', 'overworld'] }),
ActiveEffects: nbt.byteArray([]),
Scores: nbt.intArray([0, 0, 0]),
RawUUID: nbt.longArray([[0, 123456], [0, 654321]])
}, 'Entity')
// Individual builder results
console.log(nbt.byte(127)) // { type: 'byte', value: 127 }
console.log(nbt.short(32767)) // { type: 'short', value: 32767 }
console.log(nbt.int(2147483647)) // { type: 'int', value: 2147483647 }
console.log(nbt.float(3.14)) // { type: 'float', value: 3.14 }
console.log(nbt.double(1.23456789)) // { type: 'double', value: 1.23456789 }
console.log(nbt.string('hello')) // { type: 'string', value: 'hello' }
console.log(nbt.bool(true)) // { type: 'bool', value: true }
console.log(nbt.intArray([1,2,3])) // { type: 'intArray', value: [1, 2, 3] }
// Serialize to big-endian and write
const buf = nbt.writeUncompressed(entityTag)
fs.writeFileSync('entity.nbt', buf)
console.log(`Written ${buf.length} bytes`)
```
--------------------------------
### parse(data, [format]): Promise<{ parsed, type, metadata }>
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Auto-detects and parses NBT data from a Buffer or ArrayBuffer, optionally handling gzip compression. It resolves to the parsed NBT root tag, the detected format, and metadata. The format can be explicitly provided or auto-detected.
```APIDOC
## parse(data, [format]): Promise<{ parsed, type, metadata }>
### Description
Accepts a `Buffer` or `ArrayBuffer` (optionally gzip-compressed) and returns a promise resolving to the parsed NBT root tag, the detected format string, and metadata. When `format` is omitted the library tries `'big'`, `'little'`, and `'littleVarint'` in sequence until one succeeds; it also automatically skips the 8-byte Bedrock `level.dat` header. Supports an optional callback as the last argument for legacy use.
### Parameters
#### Path Parameters
None
#### Query Parameters
- **data** (Buffer | ArrayBuffer) - Required - The NBT data to parse.
- **format** (string) - Optional - The NBT format to use ('big', 'little', 'littleVarint'). If omitted, formats are tried in sequence.
### Request Example
```javascript
const fs = require('fs')
const nbt = require('prismarine-nbt')
async function main () {
const buf = fs.readFileSync('./sample/bigtest.nbt.gz')
const { parsed, type, metadata } = await nbt.parse(buf)
console.log('format:', type)
console.log('root name:', parsed.name)
}
main()
```
### Response
#### Success Response (200)
- **parsed** (object) - The parsed NBT root tag.
- **type** (string) - The detected NBT format.
- **metadata** (object) - Metadata about the parsing process, including `size` (bytes consumed) and `buffer` (decompressed buffer if applicable).
#### Response Example
```json
{
"parsed": {
"name": "Level",
"type": "compound",
"value": {
"stringTest": {
"type": "string",
"value": "HELLO WORLD THIS IS A TEST STRING ÅÄÖ!"
}
}
},
"type": "big",
"metadata": {
"size": 1234,
"buffer": ""
}
}
```
```
--------------------------------
### Parse NBT Data (Callback)
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Shows how to parse NBT data using a callback function. This method is suitable for older Node.js versions or when preferring a callback style. Errors are thrown if encountered during file reading or NBT parsing.
```javascript
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);
});
});
```
--------------------------------
### Builder Functions
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
A collection of factory functions for constructing typed NBT tags. These builders simplify the creation of complex NBT structures by allowing inline definition of tag types and values.
```APIDOC
## Builder Functions
### Description
A set of factory functions that each return a properly typed `{ type, value }` NBT tag object. Available builders: `byte`, `short`, `int`, `long`, `float`, `double`, `string`, `bool`, `comp`, `list`, `byteArray`, `shortArray`, `intArray`, `longArray`. These compose naturally for building arbitrarily deep NBT trees without manually writing type strings.
### Available Builders
- **`byte(value)`**: Creates a byte tag.
- **`short(value)`**: Creates a short tag.
- **`int(value)`**: Creates an integer tag.
- **`long(value)`**: Creates a long tag (represented as `[high32, low32]` integer pairs).
- **`float(value)`**: Creates a float tag.
- **`double(value)`**: Creates a double tag.
- **`string(value)`**: Creates a string tag.
- **`bool(value)`**: Creates a boolean tag.
- **`comp(obj, name?)`**: Creates a compound tag. Optionally accepts a name.
- **`list(value)`**: Creates a list tag.
- **`byteArray(value)`**: Creates a byte array tag.
- **`shortArray(value)`**: Creates a short array tag.
- **`intArray(value)`**: Creates an integer array tag.
- **`longArray(value)`**: Creates a long array tag.
### Example
```js
const fs = require('fs')
const nbt = require('prismarine-nbt')
// Full entity NBT structure using builder API
const entityTag = nbt.comp({
// Primitive types
id: nbt.string('minecraft:creeper'),
Health: nbt.float(20.0),
MaxHealth: nbt.float(20.0),
Age: nbt.short(0),
FuseTime: nbt.int(30),
Powered: nbt.byte(0), // 0 = not charged
ExplosionRadius: nbt.byte(3),
// Long value as [high32, low32]
UUIDMost: nbt.long([294, 1379390861]),
UUIDLeast: nbt.long([0, -123456789]),
// Nested compound
Motion: nbt.comp({
x: nbt.double(0.0),
y: nbt.double(-0.0784),
z: nbt.double(0.0)
}),
// List of compounds
Armor: nbt.list(nbt.comp([
{ id: nbt.string('minecraft:iron_helmet'), Count: nbt.byte(1), Slot: nbt.byte(103) },
{ id: nbt.string('minecraft:iron_chestplate'), Count: nbt.byte(1), Slot: nbt.byte(102) }
])),
// Array types
Tags: nbt.list({ type: 'string', value: ['hostile', 'overworld'] }),
ActiveEffects: nbt.byteArray([]),
Scores: nbt.intArray([0, 0, 0]),
RawUUID: nbt.longArray([[0, 123456], [0, 654321]])
}, 'Entity')
// Individual builder results
console.log(nbt.byte(127)) // { type: 'byte', value: 127 }
console.log(nbt.short(32767)) // { type: 'short', value: 32767 }
console.log(nbt.int(2147483647)) // { type: 'int', value: 2147483647 }
console.log(nbt.float(3.14)) // { type: 'float', value: 3.14 }
console.log(nbt.double(1.23456789)) // { type: 'double', value: 1.23456789 }
console.log(nbt.string('hello')) // { type: 'string', value: 'hello' }
console.log(nbt.bool(true)) // { type: 'bool', value: true }
console.log(nbt.intArray([1,2,3])) // { type: 'intArray', value: [1, 2, 3] }
// Serialize to big-endian and write
const buf = nbt.writeUncompressed(entityTag)
fs.writeFileSync('entity.nbt', buf)
console.log(`Written ${buf.length} bytes`)
```
```
--------------------------------
### Serialize NBT to Uncompressed Binary Buffer
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Serializes an NBT root compound tag to an uncompressed binary Buffer. The format defaults to 'big' and supports 'big', 'little', and 'littleVarint'.
```javascript
const fs = require('fs')
const nbt = require('prismarine-nbt')
// Construct a player entity NBT tag
const playerTag = nbt.comp({
playerGameType: nbt.int(0), // Survival
Score: nbt.int(1234),
Health: nbt.float(18.5),
FoodLevel: nbt.int(20),
Inventory: nbt.list(nbt.comp([
{ id: nbt.string('minecraft:diamond_sword'), Count: nbt.byte(1), Slot: nbt.byte(0) },
{ id: nbt.string('minecraft:bread'), Count: nbt.byte(32), Slot: nbt.byte(1) }
])),
Pos: nbt.list(nbt.comp([
{ type: 'double', value: 128.5 },
{ type: 'double', value: 64.0 },
{ type: 'double', value: -32.25}
]))
}, 'Player')
// Write as big-endian (Java Edition)
const javaBuf = nbt.writeUncompressed(playerTag, 'big')
fs.writeFileSync('player.nbt', javaBuf)
console.log('Java Edition bytes:', javaBuf.length)
// Write as little-endian (Bedrock Edition)
const bedrockBuf = nbt.writeUncompressed(playerTag, 'little')
fs.writeFileSync('player_bedrock.nbt', bedrockBuf)
console.log('Bedrock bytes:', bedrockBuf.length)
// Round-trip verification
const { parsed } = await nbt.parse(javaBuf, 'big')
console.log(parsed.name) // 'Player'
console.log(parsed.value.Health.value) // 18.5
console.log(parsed.value.Inventory.value.value[0].id.value) // 'minecraft:diamond_sword'
```
--------------------------------
### writeUncompressed(value, [format]): Buffer
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Serializes an NBT root compound tag to an uncompressed binary Buffer. The format defaults to 'big'. Supports 'big', 'little', and 'littleVarint'.
```APIDOC
## writeUncompressed(value, [format]): Buffer
### Description
Serializes an NBT root compound tag to an uncompressed binary `Buffer`. The format defaults to 'big'. Supports 'big', 'little', and 'littleVarint'.
### Parameters
#### Path Parameters
- **value** (object) - Required - The NBT root compound tag to serialize.
- **format** (string) - Optional - The endianness of the NBT data. Defaults to 'big'. Supported values: 'big', 'little', 'littleVarint'.
### Response
- **Buffer** - The serialized NBT data as a Buffer.
```
--------------------------------
### equal
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Compares two NBT objects for equality and returns a boolean value.
```APIDOC
## equal(nbt1, nbt2)
Checks whether two NBT objects are equal, returns a boolean.
```
--------------------------------
### parse
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Parses NBT data from a buffer, supporting automatic decompression and optional format specification. It can be used with async promises or callbacks.
```APIDOC
## parse(data, [format]): Promise<{ parsed, type, metadata: { size, buffer? } }>
## parse(data, [format,] callback)
Takes an optionally compressed `data` buffer (`Buffer` or `ArrayBuffer`) 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.
```
--------------------------------
### simplify
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Converts an NBT structure into a simplified representation by removing one level of nesting, keeping only the value. This process loses type information.
```APIDOC
## 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.
```
--------------------------------
### Async NBT Parsing with Auto-Detection
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Use this function to parse NBT data from a Buffer or ArrayBuffer. It automatically detects the NBT format (big-endian, little-endian, little-varint) and handles gzip decompression. The optional callback API is available for legacy use.
```javascript
const fs = require('fs')
const nbt = require('prismarine-nbt')
// --- Promise API (recommended) ---
async function main () {
// Parse a Java Edition .nbt file (big-endian, possibly gzipped)
const buf = fs.readFileSync('./sample/bigtest.nbt.gz')
const { parsed, type, metadata } = await nbt.parse(buf)
// type => 'big'
// metadata.size => number of bytes consumed
// metadata.buffer => decompressed Buffer
console.log('format:', type)
console.log('root name:', parsed.name) // 'Level'
console.log('root type:', parsed.type) // 'compound'
console.log('stringTest:', parsed.value.stringTest.value)
// => 'HELLO WORLD THIS IS A TEST STRING ÅÄÖ!'
// Parse a Bedrock Edition level.dat (little-endian with 8-byte header)
const bedrockBuf = fs.readFileSync('./sample/level.dat')
const { parsed: bedrockParsed, type: bedrockType } = await nbt.parse(bedrockBuf)
// type => 'little' (header detected automatically)
console.log('Bedrock format:', bedrockType)
// Force a specific format
const { parsed: forced } = await nbt.parse(buf, 'big')
console.log('forced parse name:', forced.name)
// Accept an ArrayBuffer (e.g. from fetch in the browser)
const response = await fetch('test.nbt')
const arrayBuf = await response.arrayBuffer()
const { parsed: webParsed } = await nbt.parse(arrayBuf)
console.log(webParsed)
}
// --- Callback API (legacy) ---
fs.readFile('./sample/bigtest.nbt.gz', (err, data) => {
if (err) throw err
nbt.parse(data, (error, result) => {
if (error) throw error
// result is the parsed NBT root tag
console.log(result.value.shortTest)
// => { type: 'short', value: 32767 }
console.log(result.value['nested compound test'].value.ham.value.name.value)
// => 'Hampus'
})
})
main()
```
--------------------------------
### writeUncompressed
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Serializes an NBT value into a buffer without compression. The endian format can be specified.
```APIDOC
## writeUncompressed(value, format='big')
Returns a buffer with a serialized nbt `value`.
```
--------------------------------
### parseAs(data, type, [options]): Promise<{ data, type, metadata }>
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Parses NBT data with a known, explicitly specified format, avoiding the overhead of format probing. It can automatically gunzip buffers and supports an option to disable array size validation for large arrays.
```APIDOC
## parseAs(data, type, [options]): Promise<{ data, type, metadata }>
### Description
Parses a `Buffer` with an explicitly specified format. Automatically gunzips the buffer if a gzip header is detected. Useful when the encoding is already known, avoiding the overhead of sequential format probing. The optional `options.noArraySizeCheck` flag disables array size validation for very large arrays.
### Parameters
#### Path Parameters
None
#### Query Parameters
- **data** (Buffer) - Required - The NBT data buffer to parse.
- **type** (string) - Required - The NBT format to use ('big', 'little', 'littleVarint').
- **options** (object) - Optional - Configuration options.
- **noArraySizeCheck** (boolean) - Optional - If true, disables array size validation for large arrays.
### Request Example
```javascript
const fs = require('fs')
const nbt = require('prismarine-nbt')
async function main () {
const buf = fs.readFileSync('./sample/bigtest.nbt.gz') // gzipped big-endian
const result = await nbt.parseAs(buf, 'big')
console.log(result.data.name)
}
main()
```
### Response
#### Success Response (200)
- **data** (object) - The parsed NBT data.
- **type** (string) - The specified NBT format.
- **metadata** (object) - Metadata about the parsing process.
#### Response Example
```json
{
"data": {
"name": "Level",
"type": "compound",
"value": { ... }
},
"type": "big",
"metadata": {
"size": 1234
}
}
```
```
--------------------------------
### simplify(nbt): object
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Recursively reduces the verbose { type, value } tagged representation into a plain JavaScript object. Lists become arrays, compounds become objects, and primitive tags become their bare values. This representation cannot be serialized back to NBT but is convenient for reading and logging.
```APIDOC
## simplify(nbt): object
### Description
Recursively reduces the verbose `{ type, value }` tagged representation into a plain JavaScript object. Lists become arrays, compounds become objects, and primitive tags become their bare values. This representation cannot be serialized back to NBT but is convenient for reading and logging.
### Parameters
#### Path Parameters
- **nbt** (object) - Required - The NBT data to simplify.
### Response
- **object** - A plain JavaScript object representing the simplified NBT data.
```
--------------------------------
### parseAs
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Parses NBT data from a buffer, automatically handling decompression if gzipped. Supports disabling array size checks for large arrays.
```APIDOC
## parseAs(data, type, options?= {noArraySizeCheck?: boolean})
Takes a buffer `data` and returns a parsed nbt value. If the buffer is gzipped, it will unzip the data first.
The `options` parameter is optional. When `noArraySizeCheck` is `true`, an array size check is disabled which allows for parsing of large arrays.
```
--------------------------------
### Synchronously Parse Uncompressed NBT Data
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Use this function when you have already decompressed a buffer and need a synchronous result. Defaults to big-endian. Options can disable array size checks for large data.
```javascript
const nbt = require('prismarine-nbt')
// Build and immediately re-parse a tag (round-trip test)
const original = nbt.comp({
Health: nbt.short(20),
Position: nbt.comp({
x: nbt.double(128.5),
y: nbt.double(64.0),
z: nbt.double(-32.25)
})
})
const buf = nbt.writeUncompressed(original) // serialize to Buffer
const reparsed = nbt.parseUncompressed(buf) // synchronous parse
console.log(reparsed.value.Health)
// => { type: 'short', value: 20 }
console.log(reparsed.value.Position.value.x)
// => { type: 'double', value: 128.5 }
// Little-endian round-trip
const leBuf = nbt.writeUncompressed(original, 'little')
const leReparsed = nbt.parseUncompressed(leBuf, 'little')
console.log(leReparsed.value.Health.value) // => 20
// Disable array size checks for large data
const largeBuf = nbt.writeUncompressed(nbt.comp({ Data: nbt.byteArray(new Array(100000).fill(0)) }))
const largeResult = nbt.parseUncompressed(largeBuf, 'big', { noArraySizeCheck: true })
console.log(largeResult.value.Data.value.length) // => 100000
```
--------------------------------
### Parse NBT with Known Format
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Use this function when the NBT format is already known to avoid format probing overhead. It supports explicit format specification and optional flags for handling large arrays.
```javascript
const fs = require('fs')
const nbt = require('prismarine-nbt')
async function main () {
const buf = fs.readFileSync('./sample/bigtest.nbt.gz') // gzipped big-endian
// Parse explicitly as big-endian
const result = await nbt.parseAs(buf, 'big')
console.log(result.data.name) // 'Level'
console.log(result.type) // 'big'
console.log(result.metadata.size)
// Parse a Bedrock little-endian file
const leBuf = fs.readFileSync('./sample/biome_definitions.le.nbt')
const leResult = await nbt.parseAs(leBuf, 'little')
console.log(leResult.data.type) // 'compound'
// Parse with large array support
const bigArrayBuf = fs.readFileSync('./sample/block_states.lev.nbt')
const bigResult = await nbt.parseAs(bigArrayBuf, 'little', { noArraySizeCheck: true })
console.log(bigResult.data.name)
}
main()
```
--------------------------------
### parseUncompressed(data, [format], [options]): NBT
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Synchronously parses a raw (non-gzipped) Buffer and returns the parsed NBT root tag directly. Defaults to big-endian. Use when you have already decompressed the buffer and need a synchronous result.
```APIDOC
## parseUncompressed(data, [format], [options]): NBT
### Description
Synchronously parses a raw (non-gzipped) `Buffer` and returns the parsed NBT root tag directly. Defaults to big-endian. Use when you have already decompressed the buffer and need a synchronous result.
### Parameters
#### Path Parameters
- **data** (Buffer) - Required - The NBT data buffer to parse.
- **format** (string) - Optional - The endianness of the NBT data. Defaults to 'big'. Supported values: 'big', 'little'.
- **options** (object) - Optional - Parsing options.
- **noArraySizeCheck** (boolean) - Optional - If true, disables array size checks for large data.
### Response
- **NBT** - The parsed NBT root tag.
```
--------------------------------
### Deep NBT Equality Check with `equal()`
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Compares two NBT tag objects for deep structural equality, handling all NBT types. Returns true only if both type and value are identical at every level.
```javascript
const nbt = require('prismarine-nbt')
// Identical compounds
const a = nbt.comp({ x: nbt.int(10), name: nbt.string('foo') })
const b = nbt.comp({ x: nbt.int(10), name: nbt.string('foo') })
console.log(nbt.equal(a, b)) // true
// Different value
const c = nbt.comp({ x: nbt.int(99), name: nbt.string('foo') })
console.log(nbt.equal(a, c)) // false
// Different type for same key
const d = nbt.comp({ x: nbt.short(10), name: nbt.string('foo') })
console.log(nbt.equal(a, d)) // false
// Long values ([high32, low32] pairs)
const long1 = nbt.long([0, 1234567890])
const long2 = nbt.long([0, 1234567890])
const long3 = nbt.long([0, 9999999999])
console.log(nbt.equal(long1, long2)) // true
console.log(nbt.equal(long1, long3)) // false
// Arrays
const arr1 = nbt.byteArray([1, 2, 3])
const arr2 = nbt.byteArray([1, 2, 3])
const arr3 = nbt.byteArray([1, 2, 4])
console.log(nbt.equal(arr1, arr2)) // true
console.log(nbt.equal(arr1, arr3)) // false
// Nested lists
const list1 = nbt.list(nbt.comp([{ v: nbt.int(1) }, { v: nbt.int(2) }]))
const list2 = nbt.list(nbt.comp([{ v: nbt.int(1) }, { v: nbt.int(2) }]))
console.log(nbt.equal(list1, list2)) // true
```
--------------------------------
### parseUncompressed
Source: https://github.com/prismarinejs/prismarine-nbt/blob/master/README.md
Parses NBT data from a buffer without decompression. Supports disabling array size checks for large arrays.
```APIDOC
## parseUncompressed(data, format='big', options?= {noArraySizeCheck?: boolean})
Takes a buffer `data` and returns a parsed nbt value.
The `options` parameter is optional. When `noArraySizeCheck` is `true`, an array size check is disabled which allows for parsing of large arrays.
```
--------------------------------
### Simplify NBT Tag to Plain JavaScript Object
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
Recursively reduces the verbose NBT representation into a plain JavaScript object for easier reading and logging. This simplified format cannot be serialized back to NBT.
```javascript
const nbt = require('prismarine-nbt')
// Full typed representation
const tag = nbt.comp({
Level: nbt.int(42),
Name: nbt.string('Steve'),
Skills: nbt.list(nbt.comp([
{ Attack: nbt.float(1.5), Defense: nbt.float(0.8) },
{ Attack: nbt.float(2.0), Defense: nbt.float(1.2) }
])),
Scores: nbt.intArray([100, 200, 300])
})
const simple = nbt.simplify(tag)
console.log(simple)
// {
// Level: 42,
// Name: 'Steve',
// Skills: [ { Attack: 1.5, Defense: 0.8 }, { Attack: 2, Defense: 1.2 } ],
// Scores: [ 100, 200, 300 ]
// }
console.log(simple.Level) // 42 (not { type: 'int', value: 42 })
console.log(simple.Skills[0]) // { Attack: 1.5, Defense: 0.8 }
// Useful after parse
const fs = require('fs')
const buf = fs.readFileSync('./sample/bigtest.nbt.gz')
const { parsed } = await nbt.parse(buf)
const plain = nbt.simplify(parsed)
console.log(plain.shortTest) // 32767
console.log(plain.stringTest) // 'HELLO WORLD THIS IS A TEST STRING ÅÄÖ!'
console.log(plain['nested compound test'].ham.name) // 'Hampus'
```
--------------------------------
### Deep NBT Equality Check
Source: https://context7.com/prismarinejs/prismarine-nbt/llms.txt
The `equal` function compares two NBT tag objects for deep structural equality. It handles all NBT tag types, including nested structures like compounds, lists, and arrays, returning true only if both the type and value are identical at every level.
```APIDOC
## equal(nbt1, nbt2): boolean
### Description
Compares two typed NBT tag objects for deep structural equality. Handles all tag types including `long` (represented as `[high, low]` integer pairs), arrays (`byteArray`, `intArray`, `shortArray`, `longArray`), `list`, and `compound`. Returns `true` only when both type and value are identical at every level.
### Parameters
- **nbt1** (NBTTag) - The first NBT tag object to compare.
- **nbt2** (NBTTag) - The second NBT tag object to compare.
### Returns
- **boolean** - `true` if the NBT tags are deeply equal, `false` otherwise.
### Example
```js
const nbt = require('prismarine-nbt')
// Identical compounds
const a = nbt.comp({ x: nbt.int(10), name: nbt.string('foo') })
const b = nbt.comp({ x: nbt.int(10), name: nbt.string('foo') })
console.log(nbt.equal(a, b)) // true
// Different value
const c = nbt.comp({ x: nbt.int(99), name: nbt.string('foo') })
console.log(nbt.equal(a, c)) // false
// Different type for same key
const d = nbt.comp({ x: nbt.short(10), name: nbt.string('foo') })
console.log(nbt.equal(a, d)) // false
// Long values ([high32, low32] pairs)
const long1 = nbt.long([0, 1234567890])
const long2 = nbt.long([0, 1234567890])
const long3 = nbt.long([0, 9999999999])
console.log(nbt.equal(long1, long2)) // true
console.log(nbt.equal(long1, long3)) // false
// Arrays
const arr1 = nbt.byteArray([1, 2, 3])
const arr2 = nbt.byteArray([1, 2, 3])
const arr3 = nbt.byteArray([1, 2, 4])
console.log(nbt.equal(arr1, arr2)) // true
console.log(nbt.equal(arr1, arr3)) // false
// Nested lists
const list1 = nbt.list(nbt.comp([{ v: nbt.int(1) }, { v: nbt.int(2) }]))
const list2 = nbt.list(nbt.comp([{ v: nbt.int(1) }, { v: nbt.int(2) }]))
console.log(nbt.equal(list1, list2)) // true
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.