Abstracted DisposeAsync to TagIO class
This commit is contained in:
parent
c1f6f3d721
commit
b5005ffdcc
|
@ -19,8 +19,6 @@ A CLS-compliant implementation of the Named Binary Tag (NBT) specifications (Jav
|
|||
* Xamarin.Mac 5.16
|
||||
* Xamarin.Android 10.0
|
||||
* Unity 2021.2.0b6
|
||||
* **No Dependencies:** No reliance on third-party libraries.
|
||||
* **Format Conversion:** Can convert NBT to/from JSON and XML formats.
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
|
@ -6,17 +6,18 @@ namespace SharpNBT.Tests
|
|||
public class ConversionTest
|
||||
{
|
||||
private readonly ITestOutputHelper output;
|
||||
private readonly CompoundTag tag;
|
||||
|
||||
public ConversionTest(ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
tag = TestHelper.GetTag("bigtest.nbt", CompressionType.GZip);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonOutput1()
|
||||
{
|
||||
var bigtest = TestHelper.GetTag("bigtest.nbt", CompressionType.GZip);
|
||||
output.WriteLine(bigtest.ToJsonString(true));
|
||||
output.WriteLine(tag.ToJsonString(true));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -223,11 +223,6 @@ namespace SharpNBT
|
|||
public TagBuilder AddByteArray([NotNull] IEnumerable<sbyte> values) => AddByteArray(null, values.ToArray());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new <see cref="IntArrayTag"/> with the specified <paramref name="values"/> to the tree at the current depth.
|
||||
/// </summary>
|
||||
|
@ -297,19 +292,6 @@ namespace SharpNBT
|
|||
public TagBuilder AddTag([NotNull] Tag tag)
|
||||
{
|
||||
var top = tree.Peek();
|
||||
if (top is ListTag list)
|
||||
{
|
||||
if (list.ChildType != tag.Type)
|
||||
throw new ArgumentException("Tag type does not match the child type of parent ListTag.", nameof(tag));
|
||||
if (tag.Name != null)
|
||||
throw new ArgumentException("Child tags within a ListTag must not be named.");
|
||||
}
|
||||
else if (top is CompoundTag)
|
||||
{
|
||||
if (tag.Name == null)
|
||||
throw new FormatException("Child tags within a CompoundTag must have a named.");
|
||||
}
|
||||
|
||||
top.Add(tag ?? throw new ArgumentNullException(nameof(tag)));
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace SharpNBT
|
||||
|
@ -46,6 +47,11 @@ namespace SharpNBT
|
|||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public abstract void Dispose();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously releases the unmanaged resources used by the <see cref="TagIO"/> instance.
|
||||
/// </summary>
|
||||
public abstract ValueTask DisposeAsync();
|
||||
|
||||
}
|
||||
}
|
|
@ -13,7 +13,6 @@ namespace SharpNBT
|
|||
/// <seealso cref="TagReader.TagRead"/>
|
||||
public delegate void TagReadCallback(TagReader reader, TagType type, Tag tag);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Provides methods for reading NBT data from a stream.
|
||||
/// </summary>
|
||||
|
@ -34,7 +33,7 @@ namespace SharpNBT
|
|||
private readonly bool leaveOpen;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="TagReader"/> class from the given uncompressed <paramref name="stream"/>.
|
||||
/// Creates a new instance of the <see cref="TagReader"/> class from the given <paramref name="stream"/>.
|
||||
/// </summary>
|
||||
/// <param name="stream">A <see cref="Stream"/> instance that the reader will be reading from.</param>
|
||||
/// <param name="options">Bitwise flags to configure how data should be handled for compatibility between different specifications.</param>
|
||||
|
@ -385,18 +384,7 @@ namespace SharpNBT
|
|||
return TagType.End;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reads a length-prefixed UTF-8 string from the stream.
|
||||
/// </summary>
|
||||
|
@ -449,7 +437,7 @@ namespace SharpNBT
|
|||
/// <summary>
|
||||
/// Asynchronously releases the unmanaged resources used by the <see cref="TagReader"/>.
|
||||
/// </summary>
|
||||
public async ValueTask DisposeAsync()
|
||||
public override async ValueTask DisposeAsync()
|
||||
{
|
||||
if (!leaveOpen)
|
||||
await BaseStream.DisposeAsync();
|
||||
|
|
|
@ -297,7 +297,7 @@ namespace SharpNBT
|
|||
/// <summary>
|
||||
/// Asynchronously releases the unmanaged resources used by the <see cref="TagReader"/>.
|
||||
/// </summary>
|
||||
public async ValueTask DisposeAsync()
|
||||
public override async ValueTask DisposeAsync()
|
||||
{
|
||||
await BaseStream.FlushAsync();
|
||||
if (!leaveOpen)
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace SharpNBT
|
|||
{
|
||||
typeof(TagType),
|
||||
typeof(Tag<>),
|
||||
typeof(Tag[]),
|
||||
typeof(EnumerableTag<>),
|
||||
typeof(TagContainer),
|
||||
typeof(ByteTag),
|
||||
|
@ -114,20 +115,6 @@ namespace SharpNBT
|
|||
stream.Flush();
|
||||
return Encoding.UTF8.GetString(stream.ToArray());
|
||||
}
|
||||
|
||||
public string ToXmlString()
|
||||
{
|
||||
var settings = new DataContractSerializerSettings
|
||||
{
|
||||
KnownTypes = GetKnownTypes()
|
||||
};
|
||||
var serializer = new DataContractSerializer(typeof(Tag), settings);
|
||||
using var stream = new MemoryStream();
|
||||
|
||||
serializer.WriteObject(stream, this);
|
||||
stream.Flush();
|
||||
return Encoding.UTF8.GetString(stream.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
|
||||
/// <param name="other">An object to compare with this object.</param>
|
||||
|
|
Loading…
Reference in New Issue