How to decode GZipped Base64 NBT to readable JSON in NodeJS
heres the step by step
- Install the required packages:
bashCopy code
npm install zlib buffer nbt-parser
- Write the Node.js code:
javascriptCopy code
const zlib = require(‘zlib’);
const Buffer = require(‘buffer’).Buffer;
const NbtParser = require(‘nbt-parser’);
// Function to decode GZipped Base64 NBT to JSON
async function decodeGzipBase64Nbt(gzippedBase64Nbt) {
try {
// Decode Base64
const base64Data = Buffer.from(gzippedBase64Nbt, ‘base64’);
// Decompress Gzip
const decompressedData = zlib.inflateSync(base64Data);
// Parse NBT data
const parsedData = NbtParser.parse(decompressedData);
// Convert to JSON
const jsonData = parsedData.toJson();
return jsonData;
} catch (error) {
console.error(‘Error decoding GZipped Base64 NBT:’, error);
throw error;
}
}
// Example usage
const gzippedBase64Nbt=”H4sIAAAAAAAAA+3Xy27DMBCF4f8K/G9p+xbXlrp2Dk4l0NmNQsbCqrJFItz…”; // Your GZipped Base64 NBT data here
decodeGzipBase64Nbt(gzippedBase64Nbt)
.then(jsonData => {
console.log(‘Decoded JSON:’, jsonData);
})
.catch(error => {
console.error(‘An error occurred:’, error);
});
Replace ‘Your GZipped Base64 NBT data here’ with your actual GZipped Base64 NBT data.
Read more here: Source link
