Cleaned up and documented TagReader and TagWriter classes
This commit is contained in:
parent
8a35ed1d9f
commit
9440a9bff3
|
@ -8,10 +8,16 @@ using JetBrains.Annotations;
|
|||
|
||||
namespace SharpNBT
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Delegate type for tag-related events that can occur within the <see cref="TagReader"/> class.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
[PublicAPI]
|
||||
public class TagReader : IDisposable
|
||||
{
|
||||
|
@ -28,11 +34,26 @@ namespace SharpNBT
|
|||
|
||||
private readonly bool leaveOpen;
|
||||
|
||||
public TagReader(Stream stream, bool leaveOpen) : this(stream, stream is GZipStream, leaveOpen)
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="TagReader"/> class from the given uncompressed <paramref name="stream"/>.
|
||||
/// </summary>
|
||||
/// <param name="stream">A <see cref="Stream"/> instance that the reader will be reading from.</param>
|
||||
/// <param name="leaveOpen">
|
||||
/// <paramref langword="true"/> to leave the <paramref name="stream"/> object open after disposing the <see cref="TagReader"/>
|
||||
/// object; otherwise, <see langword="false"/>.</param>
|
||||
public TagReader([NotNull] Stream stream, bool leaveOpen) : this(stream, stream is GZipStream, leaveOpen)
|
||||
{
|
||||
}
|
||||
|
||||
public TagReader(Stream stream, bool compressed, bool leaveOpen)
|
||||
/// <summary>
|
||||
/// 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="compressed">Flag indicating if the underlying <paramref name="stream"/> is compressed.</param>
|
||||
/// <param name="leaveOpen">
|
||||
/// <paramref langword="true"/> to leave the <paramref name="stream"/> object open after disposing the <see cref="TagReader"/>
|
||||
/// object; otherwise, <see langword="false"/>.</param>
|
||||
public TagReader([NotNull] Stream stream, bool compressed, bool leaveOpen)
|
||||
{
|
||||
this.leaveOpen = leaveOpen;
|
||||
if (compressed && !(stream is GZipStream))
|
||||
|
|
|
@ -10,6 +10,10 @@ using JetBrains.Annotations;
|
|||
|
||||
namespace SharpNBT
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides methods for writing NBT tags to a stream with/without compression.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public class TagWriter : IDisposable
|
||||
{
|
||||
private readonly bool leaveOpen;
|
||||
|
@ -20,13 +24,29 @@ namespace SharpNBT
|
|||
[NotNull]
|
||||
protected Stream BaseStream { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="TagWriter"/> class from the given <paramref name="stream"/>.
|
||||
/// </summary>
|
||||
/// <param name="stream">A <see cref="Stream"/> instance that the writer will be writing to.</param>
|
||||
/// <param name="leaveOpen">
|
||||
/// <paramref langword="true"/> to leave the <paramref name="stream"/> object open after disposing the <see cref="TagWriter"/>
|
||||
/// object; otherwise, <see langword="false"/>.</param>
|
||||
public TagWriter([NotNull] Stream stream, bool leaveOpen = false) : this(stream, CompressionLevel.NoCompression, leaveOpen)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="TagWriter"/> class from the given <paramref name="stream"/>.
|
||||
/// </summary>
|
||||
/// <param name="stream">A <see cref="Stream"/> instance that the writer will be writing to.</param>
|
||||
/// <param name="compression">Indicates a compression strategy to be used, if any.</param>
|
||||
/// <param name="leaveOpen">
|
||||
/// <paramref langword="true"/> to leave the <paramref name="stream"/> object open after disposing the <see cref="TagWriter"/>
|
||||
/// object; otherwise, <see langword="false"/>.</param>
|
||||
public TagWriter([NotNull] Stream stream, CompressionLevel compression, bool leaveOpen = false)
|
||||
{
|
||||
this.leaveOpen = leaveOpen;
|
||||
|
||||
if (compression != CompressionLevel.NoCompression && !(stream is GZipStream))
|
||||
BaseStream = new GZipStream(stream, compression, leaveOpen);
|
||||
else
|
||||
|
@ -256,23 +276,6 @@ namespace SharpNBT
|
|||
await Task.Run(() => WriteTag(tag));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue