nbtify
TypeScript icon, indicating that this package has built-in type declarations

1.90.1 • Public • Published

NBTify

npm downloads

Following in the footsteps of NBT.js and Prismarine-NBT, NBTify is a JavaScript library that allows for the parsing of NBT files on the web!

I started this project as a learning experience to try and make my own NBT parser from scratch. I didn't have much success in making it work reliably, so I've decided to make a brand-new fork of NBT.js that will support Bedrock Edition's little endian NBT format, one of my goals that spurred the idea for making a new library.

Prismarine-NBT seemed like a viable option to NBT.js, as it supports both Bedrock and Java formats. However, it doesn't support the browser out of the box, and bundling it seems fairly bloated just to support the browser. NBT.js is really compact, so I didn't want to take the option with more dependencies.

I really like the functionality of Prismarine-NBT and the simplicity of NBT.js, so I thought, why not meet somewhere in the middle?

NBTify has entered the chat!

Usage

Importing NBTify in the browser:

<script type="module">
  import * as NBT from "https://cdn.jsdelivr.net/npm/nbtify/dist/index.min.js";
</script>

Importing NBTify in Node:

import * as NBT from "nbtify";

Reading a file using the Fetch API in the browser:

const response: Response = await fetch("./bigtest.nbt");
const arrayBuffer: ArrayBuffer = await response.arrayBuffer();
const data: NBTData = await NBT.read(arrayBuffer);

Reading a file using the File System module in Node:

import { readFile } from "node:fs/promises";

const buffer: Buffer = await readFile("./bigtest.nbt");
const data: NBTData = await NBT.read(buffer);

Writing to a file using the File API in the browser:

const result: Uint8Array = await NBT.write(data);
const file: File = new File([result],"bigtest.nbt");

Writing to a file using the File System module in Node:

import { writeFile } from "node:fs/promises";

const result: Uint8Array = await NBT.write(data);
await writeFile("./bigtest.nbt",result);

Package Sidebar

Install

npm i nbtify

Weekly Downloads

30

Version

1.90.1

License

MIT

Unpacked Size

119 kB

Total Files

39

Last publish

Collaborators

  • offroaders123