Giter VIP home page Giter VIP logo

nbt-js's Introduction

Note: this repository is archived.

When I started this project, I was deeply involved with both Minecraft and JavaScript. Since then, my involvement with both has waned and the JavaScript landscape has moved at an incredible pace.

Without a clear vision and no dogfooding, I'm no longer the right maintainer for this project and hence have archived this repository. There are a good few forks out there which I encourage anyone to seek out and give a try.

Apologetically yours,

Sijmen


NBT.js Build Status

By Sijmen Mulder and a host of wonderful contributors.

NBT.js is a JavaScript parser and serializer for NBT archives, for use with Node.js or the browser.

Usage

After var nbt = require('nbt') or <script src="nbt.js"></script>, you can use nbt.parse(data, callback) to convert NBT data into a regular JavaScript object.

var fs = require('fs'),
    nbt = require('nbt');

var data = fs.readFileSync('fixtures/bigtest.nbt.gz');
nbt.parse(data, function(error, data) {
    if (error) { throw error; }

    console.log(data.value.stringTest.value);
    console.log(data.value['nested compound test'].value);
});

If the data is gzipped, it is automatically decompressed first. When running in the browser, window.zlib is required for this to work.

Tag names are copied verbatim, and as some names are not valid JavaScript names, use of the indexer may be required – such as with the nested compound test in the example above.

API documentation

The full documentation generated with JSDoc is available in the docs/ directory and online:

http://sjmulder.github.io/nbt-js/

Development and testing

npm install  # Install development dependencies
make check   # Check code quality with jshint and run tests
make watch   # Automatically runs 'make check' every few seconds
make doc     # Regenerate the documentation in docs/

Copyright

I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.

In case this is not legally possible: I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.

nbt-js's People

Contributors

deathcap avatar offroaders123 avatar roblabla avatar rom1504 avatar sjmulder avatar sourcehunter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nbt-js's Issues

Pure js version

Could you make a pure javascript version (ie no need for node.js).
The decoding from compressed data is not needed.

I'm asking because i'm working on a webview for the supercircuit mod and have no access to a jquery server. I tried to refactor your code before, but i failed.

What is window.zlib?

Hello,

It says that you need to use window.zlib in order to compress/decompress in the browser but I cannot for the life of me work out what this is. I am probably just being stupid but if you pointed me in the correct direction it would be much appreciated.

Thanks.

Investigate if data isn’t being copied unnecessarily

Since switching from Buffer to ArrayBuffer, Uint8Array and DataView in an attempt to be browser compatible there is a lot of wrapping and conversion going on between these types.

It could be worth checking if data isn’t being copied left and right.

Some points to focus on:

  • nbt.Reader() initialisation
  • nbt.Writer() initialisation
  • nbt.parse()’s zlib code

Command line tools

E.g.:

nbt-json <sample.nbt | json-nbt >sample.json

Would be useful to combine with jq.

Unicode in gzip archives isn’t handled correctly

$ cd sample/
$ node sample.js 
HELLO WORLD THIS IS A TEST STRING ���!
{ ham: { name: 'Hampus', value: 0.75 },
  egg: { name: 'Eggbert', value: 0.5 } }

The string should’ve been:

HELLO WORLD THIS IS A TEST STRING ÅÄÖ!

nbt.Reader.byte() should be unsigned

I'm parsing Minecraft world data and occasionally get unexpected results for block IDs (which are 0-255). I tried changing nbt.Reader.byte() to use Buffer.readUInt8 instead of Buffer.readInt8 and the behaviour was then as expected.

If Minecraft is only storing unsigned integers with the NBT byte tag, I think it'd be safe to assume the byte tag is only intended to store unsigned integers.

Support string and array data

parse(), parseUncompressed(), and Reader() accept either a Buffer or ArrayBuffer.

  • They should allow strings and arrays, validating that all elements lie within the [0, 255] range
  • If the data is not an ArrayBuffer, Buffer, string or array an error must be raised

Browser support

NBT.js currently does not work in the browser. I think it’s easiest to use a pre-existing Buffer module, if there is one. The test suite should then also be made to run in the browser.

Serializer?

Description says package is a parser and serializer but I only see a parse function... Did i miss something?

Bedrock NBT: Little Endian Parsing

Hey there,

I was trying to parse the level.dat file for a Bedrock Edition world save, and it doesn't seem to be working correctly. I think this is due to Bedrock's difference in NBT format implementation to Java Edition. I have heard that Bedrock NBT files use little-endian rather than big-endian, and I haven't yet been able to figure out how to either convert the Bedrock NBT to big-endian, or make an edit to your library to be able to parse little-endian data. Would you happen to know how this could be implemented? I found the library Prismarine-NBT for NodeJS, and it can parse both big-endian and little-endian types automatically, and I was hoping to add support for something like that with your library as well. I have the goal of parsing NBT in the browser, on the front end, and your library seems to be more ready for that than other NodeJS-focused NBT parsers out there.

*side note:
The level.dat file for a Bedrock Edition world save starts with a few bytes that aren't part of the NBT data, and are version metadata that describe info about the world. I found out about this here. I also attached the level.dat file I have been hoping to open with your library.

hello_world.nbt (Big-endian, parses correctly)
level.dat (Little-endian, errors out)
Note: GitHub wouldn't let me upload the files with .nbt and .dat extensions, so I changed them to .txt just to upload them. You can change them back to .nbt and .dat each, once downloaded.

I'd love to help out, this is a great project!
Brandon Bennett

Write compressed nbt data

I can't find any informations about how to write compressed nbt data.
I mean there is a parse-function for compressed nbt data, then there should be also a compressed write function or not?

EDIT: I just tried to extract and recompress some nbt-data using imaya's gzip.min.js but just received rubbish.

Steps to recreate:
1. Apply atob to the raw data (Needed because the data is base64 encrypted)
2. Parse the data with nbt.parse (I used imayas's gunzip.min.js to decompress it)
3. Export the nbt data with nbt.write
4. Use gzip to compress the data
5. Apply btoa to the exported data 

64-bit integers overflow

Values from TAG_Long tags may overflow if the value is negative or if it does not fit in 32 bits. This is a limitation of the library used for unpacking binary values.

RangeError when attempting to parse mcedit schematic file

nbt.js:403 Uncaught RangeError: Offset is outside the bounds of the DataView
at DataView.getInt8 ()
at nbt.Reader.read (nbt.js:403)
at Object.nbt.parseUncompressed (nbt.js:599)
at Object.nbt.parse (nbt.js:647)

I've tried several different schematics from several different websites, and they all give the same error. I've attached a schematic file that gives the error. According to the mcedit wiki, the schematic file format follows the nbt format, so I was hoping this script would work.

Webpage is served from a Debian server, and the script is being run via latest Chrome, on windows 10.

simple-contemporary.zip

Datatype long gets parsed wrong

While troubleshooting my nbt importer/exporter I discovered that all my longs get parsed as a array.
Here is a JSON example (this should be a long from a BlockVector):
{"type":"long","value":[64,0]}
But the expected output is:
{"type":"long","value":274877906944}

Here is the nbt-data.
The wrong data can be found at:

.value.components.value.value[2].__pos

More longs at:
.value.components.value.value[1].__pos
.value.components.value.value[0].__pos

Host documentation somewhere

There is a doc/ directory with a full reference but it’s more accessible if it’s hosted somewhere, like on GitHub Pages.

Make parseUncompressed() return the same format always again

In 16e6c1a I changed parseUncompressed() to return either { <name>: <value> } or <value> rather than { root: <name>, value: <value> } because it looked cleaner, but I've come back from that as indeed the benefits of having it return the same structure always are bigger, especially wrt symmetry with writeUncompressed().

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.