Skip to content

Class NbtFile

Namespace: Void.Minecraft.Nbt
Assembly: Void.Minecraft.dll

Provides static convenience methods for working with NBT-formatted files, including both reading and writing.

public static class NbtFile

Inheritance

objectNbtFile

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Methods

OpenRead(string, FormatOptions, CompressionType)

Opens an existing NBT file for reading, and returns a instance for it.

public static TagReader OpenRead(string path, FormatOptions options, CompressionType compression = CompressionType.AutoDetect)

Parameters

path string

The path of the file to open for reading.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

compression CompressionType

Indicates the compression algorithm used to compress the file.

Returns

TagReader

A instance for the file stream.

Remarks

File compression will be automatically detected and handled when necessary.

OpenWrite(string, FormatOptions, CompressionType, CompressionLevel)

Opens an existing NBT file or creates a new one if it does not exist, and returns a instance for it.

public static TagWriter OpenWrite(string path, FormatOptions options, CompressionType type = CompressionType.GZip, CompressionLevel level = CompressionLevel.Fastest)

Parameters

path string

The path of the file to open for writing.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

type CompressionType

A flag indicating the type of compression to use.

level CompressionLevel

A flag indicating the compression strategy that will be used, if any.

Returns

TagWriter

A instance for the file stream.

Read<T>(string, FormatOptions, CompressionType)

Reads a file at the given path and deserializes the top-level contained in the file.

public static T Read<T>(string path, FormatOptions options, CompressionType compression = CompressionType.AutoDetect) where T : Tag, ICollection<Tag>

Parameters

path string

The path to the file to be read.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

compression CompressionType

Indicates the compression algorithm used to compress the file.

Returns

T

The deserialized instance.

Type Parameters

T

The type of tag to deserialize.

Read(string, FormatOptions, CompressionType)

Reads a file at the given path and deserializes the top-level contained in the file.

public static CompoundTag Read(string path, FormatOptions options, CompressionType compression = CompressionType.AutoDetect)

Parameters

path string

The path to the file to be read.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

compression CompressionType

Indicates the compression algorithm used to compress the file.

Returns

CompoundTag

The deserialized instance.

ReadAsync<T>(string, FormatOptions, CompressionType)

Asynchronously reads a file at the given path and deserializes the top-level contained in the file.

public static Task<T> ReadAsync<T>(string path, FormatOptions options, CompressionType compression = CompressionType.AutoDetect) where T : Tag, ICollection<Tag>

Parameters

path string

The path to the file to be read.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

compression CompressionType

Indicates the compression algorithm used to compress the file.

Returns

Task<T>

The deserialized instance.

Type Parameters

T

ReadAsync(string, FormatOptions, CompressionType)

Asynchronously reads a file at the given path and deserializes the top-level contained in the file.

public static Task<CompoundTag> ReadAsync(string path, FormatOptions options, CompressionType compression = CompressionType.AutoDetect)

Parameters

path string

The path to the file to be read.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

compression CompressionType

Indicates the compression algorithm used to compress the file.

Returns

Task<CompoundTag>

The deserialized instance.

Write(string, CompoundTag, FormatOptions, CompressionType, CompressionLevel)

Writes the given tag to a file at the specified path.

public static void Write(string path, CompoundTag tag, FormatOptions options, CompressionType type = CompressionType.GZip, CompressionLevel level = CompressionLevel.Fastest)

Parameters

path string

The path to the file to be written to.

tag CompoundTag

The top-level instance to be serialized.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

type CompressionType

A flag indicating the type of compression to use.

level CompressionLevel

Indicates a compression strategy to be used, if any.

Write(string, ListTag, FormatOptions, CompressionType, CompressionLevel)

Writes the given tag to a file at the specified path.

public static void Write(string path, ListTag tag, FormatOptions options, CompressionType type = CompressionType.GZip, CompressionLevel level = CompressionLevel.Fastest)

Parameters

path string

The path to the file to be written to.

tag ListTag

The top-level instance to be serialized.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

type CompressionType

A flag indicating the type of compression to use.

level CompressionLevel

Indicates a compression strategy to be used, if any.

WriteAsync(string, CompoundTag, FormatOptions, CompressionType, CompressionLevel)

Asynchronously writes the given tag to a file at the specified path.

public static Task WriteAsync(string path, CompoundTag tag, FormatOptions options, CompressionType type = CompressionType.GZip, CompressionLevel level = CompressionLevel.Fastest)

Parameters

path string

The path to the file to be written to.

tag CompoundTag

The top-level instance to be serialized.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

type CompressionType

A flag indicating the type of compression to use.

level CompressionLevel

Indicates a compression strategy to be used, if any.

Returns

Task

WriteAsync(string, ListTag, FormatOptions, CompressionType, CompressionLevel)

Asynchronously writes the given tag to a file at the specified path.

public static Task WriteAsync(string path, ListTag tag, FormatOptions options, CompressionType type = CompressionType.GZip, CompressionLevel level = CompressionLevel.Fastest)

Parameters

path string

The path to the file to be written to.

tag ListTag

The top-level instance to be serialized.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

type CompressionType

A flag indicating the type of compression to use.

level CompressionLevel

Indicates a compression strategy to be used, if any.

Returns

Task