Skip to content

Instantly share code, notes, and snippets.

@robere2
Last active March 12, 2020 10:03
Show Gist options
  • Save robere2/f04132c52ea79db089fc214b67c81885 to your computer and use it in GitHub Desktop.
Save robere2/f04132c52ea79db089fc214b67c81885 to your computer and use it in GitHub Desktop.
Example on how to unzip (but not parse) compressed NBT data in Javascript
let fs = require('fs');
let zlib = require('zlib');
let invData = [31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -29, 98, 96, -32, 100, 96, -52, -28, 98, 96, 96, 80, 97, 98, 96, -54, 76, 97, 100, 98, 100, 96,
117, -50, 47, -51, 43, 97, -28, 98, 96, 46, 73, 76, 103, 100, -32, 14, -51, 75, 42, 74, 77, -52, 78, 76, -54, 73, 101, 100, 102, -32, -12,
-56, 76, 73, 117, -53, 73, 76, 47, 6, 106, -6, -57, -59, -64, -98, -110, 89, 92, -112, -109, 88, -55, -55, -64, -30, -109, 95, -108, -54, 1,
20, 101, 97, -32, 57, -76, -36, 60, 32, -75, 40, 91, 33, -77, 36, 53, 23, 40, 34, 124, 104, -71, -91, -74, -71, -126, 99, 73, 73, 98, 114,
-74, -126, 75, 98, 110, 98, 122, 42, 3, 31, 80, 16, -55, 108, 6, 6, 38, 6, 54, -88, 20, -120, 13, 114, 13, 43, 126, -41, -96, -24, -128, 0,
-120, 62, 54, -104, 62, 5, 76, 21, -40, 1, 0, 111, 21, -87, 83, 10, 1, 0, 0];
let buf = Buffer.from(invData);
let unzipped = zlib.gunzipSync(buf);
fs.writeFile("inv.dat", unzipped, (err) => {
if(err)
console.error(err);
console.log("Done writing");
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment