"Sputnik" help  
Sputnik Help
NbtCompoundWriteSafeFile(<nbtCompound>, <file>, [<compress>])


Writes an NBT compound to a file safely by performing additional checks.


<nbtCompound> The NBT compound to write to the file.
<file> The path to the file where the NBT compound will be written.
<compress> Optional. If set to true, the NBT compound will be compressed using GZip before writing to the file. Defaults to false.

Return Value

Success: Returns true if the NBT compound is written to the file successfully and passes the integrity check.
Failure: Returns false if there is an error during the write operation or if the integrity check fails.


The NbtCompoundWriteSafeFile function writes an NBT compound to a file while ensuring data integrity. It performs additional steps to guarantee that the file contains the exact byte-for-byte representation of the NBT compound.

First, the function writes the NBT compound to the file using NbtCompoundWriteFile. Then, it reads the file back using NbtCompoundReadFile. Finally, it compares the original NBT compound with the one read from the file to verify their byte-for-byte equality.

If the file write operation is successful and the integrity check passes, the function returns true. Otherwise, it returns false.

Note: The integrity check ensures that the written file accurately represents the NBT compound. However, it does not guarantee the file's security or protection against tampering.



Example of usage:

my $nbt = NbtNew(@NbtCompound);
NbtCompoundSet($nbt, "Cat", "Meow");
NbtCompoundSet($nbt, "Dog", "Woof");

my $file = FileCreateTemp();
NbtCompoundWriteSafeFile($nbt, $file);

my $nbtRead = NbtCompoundReadFile($file);
say $nbtRead;
foreach(my $k => my $v in $nbtRead)
    say $k . " -> " . $v;

// {NBTTag;Compound::[Cat:Meow,Dog:Woof]}
// Cat -> Meow
// Dog -> Woof


Cheryl (uberfox@hotmail.com)