Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function writeCompressedNbt (value, buffer, offset) {
if (value === undefined) {
buffer.writeInt16BE(-1, offset)
return offset + 2
}
const nbtBuffer = Buffer.alloc(sizeOfNbt(value))
nbt.proto.write(value, nbtBuffer, 0, 'nbt')
const compressedNbt = zlib.gzipSync(nbtBuffer) // TODO: async
compressedNbt.writeUInt8(0, 9) // clear the OS field to match MC
buffer.writeInt16BE(compressedNbt.length, offset)
compressedNbt.copy(buffer, offset + 2)
return offset + 2 + compressedNbt.length
}
function sizeOfNbt (value) {
return nbt.proto.sizeOf(value, 'nbt')
}