From 9440a9bff3f67517eeb8a5cd923785f94261b6cd Mon Sep 17 00:00:00 2001 From: ForeverZer0 Date: Mon, 23 Aug 2021 04:24:17 -0400 Subject: [PATCH] Cleaned up and documented TagReader and TagWriter classes --- SharpNBT/TagReader.cs | 27 ++++++++++++++++++++++++--- SharpNBT/TagWriter.cs | 39 +++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/SharpNBT/TagReader.cs b/SharpNBT/TagReader.cs index ea81f74..0a32451 100644 --- a/SharpNBT/TagReader.cs +++ b/SharpNBT/TagReader.cs @@ -8,10 +8,16 @@ using JetBrains.Annotations; namespace SharpNBT { - + /// + /// Delegate type for tag-related events that can occur within the class. + /// + /// public delegate void TagReadCallback(TagReader reader, TagType type, Tag tag); + /// + /// Provides methods for reading NBT data from a stream. + /// [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) + /// + /// Creates a new instance of the class from the given uncompressed . + /// + /// A instance that the reader will be reading from. + /// + /// to leave the object open after disposing the + /// object; otherwise, . + public TagReader([NotNull] Stream stream, bool leaveOpen) : this(stream, stream is GZipStream, leaveOpen) { } - public TagReader(Stream stream, bool compressed, bool leaveOpen) + /// + /// Creates a new instance of the class from the given . + /// + /// A instance that the reader will be reading from. + /// Flag indicating if the underlying is compressed. + /// + /// to leave the object open after disposing the + /// object; otherwise, . + public TagReader([NotNull] Stream stream, bool compressed, bool leaveOpen) { this.leaveOpen = leaveOpen; if (compressed && !(stream is GZipStream)) diff --git a/SharpNBT/TagWriter.cs b/SharpNBT/TagWriter.cs index c886943..d0a7982 100644 --- a/SharpNBT/TagWriter.cs +++ b/SharpNBT/TagWriter.cs @@ -10,6 +10,10 @@ using JetBrains.Annotations; namespace SharpNBT { + /// + /// Provides methods for writing NBT tags to a stream with/without compression. + /// + [PublicAPI] public class TagWriter : IDisposable { private readonly bool leaveOpen; @@ -20,13 +24,29 @@ namespace SharpNBT [NotNull] protected Stream BaseStream { get; } + /// + /// Creates a new instance of the class from the given . + /// + /// A instance that the writer will be writing to. + /// + /// to leave the object open after disposing the + /// object; otherwise, . public TagWriter([NotNull] Stream stream, bool leaveOpen = false) : this(stream, CompressionLevel.NoCompression, leaveOpen) { } + /// + /// Creates a new instance of the class from the given . + /// + /// A instance that the writer will be writing to. + /// Indicates a compression strategy to be used, if any. + /// + /// to leave the object open after disposing the + /// object; otherwise, . 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 @@ -255,24 +275,7 @@ namespace SharpNBT { await Task.Run(() => WriteTag(tag)); } - - - - - - - - - - - - - - - - - - + /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. ///