Package Exports
- @xmcl/nbt
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@xmcl/nbt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Nbt Module
This is a sub-module belong to minecraft-launcher-core module. You can still use this individually.
Usage
Read/Write NBT
You can simply deserialize/serialize nbt.
import { NBT } from "@xmcl/nbt";
const fileData: Buffer;
// compressed = undefined will not perform compress algorithm
// compressed = true will use gzip algorithm
const compressed: true | "gzip" | "deflate" | undefined;
const readed: NBT.TypedObject = await NBT.deserialize(fileData, { compressed });
// NBT.Persistence.TypedObject is just a object with __nbtPrototype__ defining its nbt type
// After you do the modification on it, you can serialize it back to NBT
const buf: Buffer = await NBT.serialize(readed, { compressed });
// or use serializer style
const serial = NBT.createSerializer()
.register("server", {
name: NBT.TagType.String,
host: NBT.TagType.String,
port: NBT.TagType.Int,
icon: NBT.TagType.String,
});
const serverInfo: any; // this doesn't require the js object to be a TypedObject
const serialized: Buffer = await serial.serialize(serverInfo, "server");