sjmulder / nbt-js

NBT.js – a JavaScript parser for NBT archives
http://sjmulder.github.io/nbt-js/
Other
73 stars 19 forks source link

RangeError when attempting to parse mcedit schematic file #39

Closed lancewellspring closed 5 years ago

lancewellspring commented 5 years ago

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

lancewellspring commented 5 years ago

The problem was on my end. I was returning the schematic file from Node.js Express, and the jQuery ajax function I was using was interpreting it as a string. Using the code found at: https://www.henryalgus.com/reading-binary-files-using-jquery-ajax/, I was able to get the data as an ArrayBuffer instead, which fixed the problem.

As a side note, nbt.js doesn't work properly in the browser. It expects window.zlib to be available, but I couldn't figure out how to get that working. So I just added a reference to pako, and modified nbt.js slightly to use pako.inflate instead of zlib.gunzip.