New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@xmcl/nbt

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xmcl/nbt

NBT serialization and deserialization

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25
decreased by-50.98%
Maintainers
1
Weekly downloads
 
Created
Source

Nbt Module

npm version Downloads Install size npm Build Status

Provide function to read NBT binary format to json.

Usage

Read and Write NBT

You can simply deserialize/serialize nbt.

    import { serialize, deserialize } 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: any = await deserialize(fileData, { compressed });
    // The deserialize return object contain NBTPrototype property which define its nbt type
    // After you do the modification on it, you can serialize it back to NBT
    const buf: Buffer = await serialize(readed, { compressed });

You can use class with annotation (decorator) to serialize/deserialize the type consistently.

Suppose you are reading the servers.dat. You can have:

import { serialize, deserialize, TagType } from "@xmcl/nbt";

class ServerInfo {
    @TagType(TagType.String)
    icon: string = "";
    @TagType(TagType.String)
    ip: string = "";
    @TagType(TagType.String)
    name: string = "";
    @TagType(TagType.Byte)
    acceptTextures: number = 0;
}

class Servers {
    @TagType([ServerInfo])
    servers: ServerInfo[] = []
}

// read
// explict tell the function to deserialize into the type Servers
const servers = await deserialize(data, { type: Servers });
const infos: ServerInfo[] = servers.servers;

// write
const servers: Servers;
const binary = await serialize(servers);

Keywords

FAQs

Package last updated on 14 Mar 2020

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