Options
All
  • Public
  • Public/Protected
  • All
Menu

binary-nbt

Index

Variables

Const NBTListSymbol

NBTListSymbol: unique symbol = Symbol("NBT list type")

The Symbol used to store the type of the item in a TAG_LIST. This is attached as a property on the Array.

Const NBTNameSymbol

NBTNameSymbol: unique symbol = Symbol("NBT node name")

The Symbol used to store the root name property of an NBT file.

Const NBTTypeSymbol

NBTTypeSymbol: unique symbol = Symbol("NBT node type")

The Symbol used to store the NBT Tag Type of a JavaScript Object.

To set this for your own objects, use createNBTType. This can be inferred in a majority of cases.

Const byte

byte: function = tagSpecifier<number>(TagType.TAG_BYTE)

Specify that a number should be serialized as a TAG_BYTE

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const byteArray

byteArray: function = tagSpecifier<number[]>(TagType.TAG_BYTE_ARRAY)

Specify that a number[] should be serialized as a TAG_BYTE_ARRAY.

All the numbers must be integers between -128 and 127, otherwise an error is thrown upon serialization.

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const compound

compound: function = tagSpecifier<any>(TagType.TAG_COMPOUND)

Specify that a value any should be serialized as a TAG_COMPOUND.

This has no effect on any resulting NBT, and is only included for consistency

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const double

double: function = tagSpecifier<number>(TagType.TAG_DOUBLE)

Specify that a number should be serialized as a TAG_DOUBLE

This is pointless as numbers, are serialized as TAG_DOUBLE unless specified otherwise

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const float

float: function = tagSpecifier<number>(TagType.TAG_FLOAT)

Specify that a number should be serialized as a TAG_FLOAT

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const int

int: function = tagSpecifier<number>(TagType.TAG_INT)

Specify that a number should be serialized as a TAG_INT

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const intArray

intArray: function = tagSpecifier<number[]>(TagType.TAG_INT_ARRAY)

Specify that a number[] should be serialized as a TAG_INT_ARRAY.

All the numbers must be integers between -2,147,483,648 and 2,147,483,647, otherwise an error will be thrown upon serialization.

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const list

list: function = tagSpecifier<any[]>(TagType.TAG_LIST)

Specify that an array should be serialized as a TAG_LIST.

All the items must have the same TAG_ type, otherwise an error will be thrown upon serialisation. Where possible, this is automatically extracted.

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const long

long: function = tagSpecifier<number | Long>(TagType.TAG_LONG)

Specify that this number should be serialized as a TAG_LONG

This is pointless on a Long, which are serialized as TAG_LONG unless specified otherwise

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const longArray

longArray: function = tagSpecifier<Long[]>(TagType.TAG_LONG_ARRAY)

Specify that a given Long[] should be serialized as a TAG_LONG_ARRAY

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const short

short: function = tagSpecifier<number>(TagType.TAG_SHORT)

Specify that a number should be serialized as a TAG_SHORT

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Const string

string: function = tagSpecifier<string>(TagType.TAG_STRING)

Specify that a string should be serialized as a TAG_STRING

Type declaration

    • <V>(value: V): V
    • Type parameters

      • V: T

      Parameters

      • value: V

      Returns V

Functions

createNBTType

  • createNBTType<T>(value: T, type: TagType): T
  • Create a value which is to be serialized as a specific type.

    Type parameters

    • T

    Parameters

    • value: T
    • type: TagType

      The TagType which is to be serialized

    Returns T

deserializeCompressedNBT

  • deserializeCompressedNBT<T>(buffer: Buffer, useMaps?: boolean, named?: boolean): Promise<T>
  • Same as deserializeNBT, but if buffer contains compressed data, it will be uncompressed automatically. If this behaviour is not required, use the synchronous deserializeNBT function instead.

    throws

    If the NBT is malformed. E.g. an invalid tag type is specified or the NBT is truncated.

    throws

    If the compression is invalid

    Type parameters

    • T

    Parameters

    • buffer: Buffer

      The buffer to deserialize the NBT from.

    • Default value useMaps: boolean = false

      to use ES6 maps for compounds. This is useful to retain insertion order

    • Default value named: boolean = true

      Whether or not the root is named. For example, a typical structure is {"":}.

    Returns Promise<T>

deserializeNBT

  • deserializeNBT<T>(buffer: Buffer, useMaps?: boolean, named?: boolean): T
  • Deserialize an NBT value from buffer. This returns an object which is the closest JavaScript equivalent of the input. TAG_LONGs, which cannot be losslessly represented in a JavaScript number, are deserialized as Longs from the long package.

    Deserialize an NBT value from buffer. This returns an object which is the closest JavaScript equivalent of the input. TAG_LONGs, which cannot be losslessly represented in a JavaScript number, are deserialized as Longs from the long package.

    The resulting object can be serialized into the same NBT value. This is explained fully in the README.

    throws

    If the NBT is malformed. E.g. an invalid tag type is specified or the NBT is truncated.

    Type parameters

    • T

    Parameters

    • buffer: Buffer

      The buffer to deserialize the NBT from

    • Default value useMaps: boolean = false

      Whether to use ES6 Maps for compounds. This is useful to retain insertion order

    • Default value named: boolean = true

      Whether or not the root is named. For example, a typical structure is {"":}. (Reasoning for this required)

    Returns T

serializeNBT

  • serializeNBT(value: unknown): Buffer
  • Serialize from a JavaScript value into an equivalent NBT value.

    If value this was deserialized from NBT using deserializeNBT, this should create an identical NBT value to the one it was originally deserialized from(1).

    (1) This is only guaranteed to be true if the useMaps flag was set, due to the non-guaranteed iteration order of the object primitive.

    Parameters

    • value: unknown

    Returns Buffer

serializeNBTDebug

  • serializeNBTDebug(value: unknown, defaultBuffer?: Buffer): Buffer
  • Serialize value into defaultBuffer, throwing an error if any different value is written.

    Only intended for use in testing and debugging of this library. Changing the signature of this function MAY occur in any non-patch release

    Parameters

    • value: unknown
    • Optional defaultBuffer: Buffer

    Returns Buffer

Generated using TypeDoc