Module: RubyCraft::NbtHelper

Extended by:
ByteConverter, ZlibHelper
Defined in:
lib/rubycraft/nbt_helper.rb

Overview

Handles converting bytes to/from nbt regions, which are compressesed/decompress

Class Method Summary collapse

Methods included from ByteConverter

arrayToIO, bytesToInt, concat, intBytes, pad, stringToByteArray, stringToIo, toByteString

Methods included from ZlibHelper

compress, decompress

Class Method Details

.fromNbt(bytes) ⇒ Object



38
39
40
# File 'lib/rubycraft/nbt_helper.rb', line 38

def fromNbt(bytes)
  NBTFile.read stringToIo decompress toByteString bytes
end

.toBytes(nbt) ⇒ Object



42
43
44
45
46
47
# File 'lib/rubycraft/nbt_helper.rb', line 42

def toBytes(nbt)
  output = StringIO.new
  name, body = nbt
  NBTFile.write(output, name, body)
  stringToByteArray compress output.string
end