public static CompoundTag ReadZLIBFile(string fileName, NBTEndian endian = NBTEndian.LITTLE_ENDIAN) { byte[] bytes = File.ReadAllBytes(fileName); byte[] payload = new byte[0]; using (MemoryStream ms = new MemoryStream(bytes)) { if (ms.ReadByte() != 0x78) { throw new FormatException(); } ms.ReadByte(); using (ZlibStream ds = new ZlibStream(ms, CompressionMode.Decompress, false)) { MemoryStream c = new MemoryStream(); ds.CopyTo(c); payload = c.ToArray(); c.Close(); } } CompoundTag tag = new CompoundTag(); using (NBTStream nbt = new NBTStream(payload, endian)) { tag.Read(nbt); return(tag); } }
public static CompoundTag ReadZLIBFile(byte[] buffer, ByteOrder order = ByteOrder.Little) { byte[] bytes = buffer; byte[] payload = new byte[0]; using (MemoryStream ms = new MemoryStream(bytes)) { if (ms.ReadByte() != 0x78) { throw new FormatException(); } ms.ReadByte(); using (ZlibStream ds = new ZlibStream(ms, CompressionMode.Decompress, false)) { MemoryStream c = new MemoryStream(); ds.CopyTo(c); payload = c.ToArray(); c.Close(); } } CompoundTag tag = new CompoundTag(); using (NBTStream nbt = new NBTStream(payload, order)) { tag.Read(nbt); return(tag); } }
public static CompoundTag ReadRawFile(string fileName, NBTEndian endian = NBTEndian.LITTLE_ENDIAN) { CompoundTag tag = new CompoundTag(); byte[] bytes = File.ReadAllBytes(fileName); using (NBTStream stream = new NBTStream(bytes, endian)) { tag.Read(stream); } return(tag); }
public static CompoundTag ReadRawFile(string fileName, ByteOrder order = ByteOrder.Little) { CompoundTag tag = new CompoundTag(); byte[] bytes = File.ReadAllBytes(fileName); using (NBTStream stream = new NBTStream(bytes, order)) { tag.Read(stream); } return(tag); }
public static CompoundTag ReadGZIPFile(string fileName, NBTEndian endian = NBTEndian.LITTLE_ENDIAN) { byte[] bytes = File.ReadAllBytes(fileName); byte[] payload = new byte[0]; using (MemoryStream ms = new MemoryStream(bytes)) { using (GZipStream gz = new GZipStream(ms, CompressionMode.Decompress, true)) { MemoryStream c = new MemoryStream(); gz.CopyTo(c); payload = c.ToArray(); c.Close(); } } CompoundTag tag = new CompoundTag(); using (NBTStream nbt = new NBTStream(payload, endian)) { tag.Read(nbt); return(tag); } }