NbtFile
Creating an NbtFile
After obtaining a Uint8Array of the file, you can give it to NbtFile.read to create an NbtFile.
const response = await fetch('./example.nbt')
const arrayBuffer = await response.arrayBuffer()
const file = NbtFile.read(new Uint8Array(arrayBuffer, {}))
Alternatively, empty files can be created with NbtFile.create.
const file = NbtFile.create({})
Options
In both cases, you can pass an options argument. For each options property, if it is not given NbtFile.read will try to detect it from the binary data. littleEndian is not automatically detected, it always defaults to false.
| Name | Type | Default |
|---|---|---|
name | string | '' |
compression | 'gzip' | 'zlib' | 'none' | none |
littleEndian | boolean | false |
bedrockHeader | number | boolean | undefined |
Properties
| Name | Type |
|---|---|
name | string |
root | NbtCompound |
compression | 'gzip' | 'zlib' | 'none' |
littleEndian | boolean |
bedrockHeader | number | undefined |
Methods
write()
Turns this file into a Uint8Array. Writes the bedrockHeader if not undefined. Compresses the data if compression is not 'none'.
const array = file.write()
toJson()
Serializes the file to a format which can be represented by JSON. This can be necessary when using workers.
const json = file.toJson()
// send the data to a different worker
const file2 = NbtFile.fromJson(json)