/// <summary>
        /// Whether or not the current value can be streamed
        /// </summary>
        /// <returns>True if the current value can be streamed, otherwise false</returns>
        public virtual bool CanStream()
        {
            IJsonStreamReader streamReader = this.innerReader as IJsonStreamReader;

            if (!this.isBuffering && streamReader != null)
            {
                return(streamReader.CanStream());
            }

            return(this.Value is string || this.Value == null || this.NodeType == JsonNodeType.StartArray || this.NodeType == JsonNodeType.StartObject);
        }
        /// <summary>
        /// Creates a TextReader for reading a text value.
        /// </summary>
        /// <returns>A TextReader for reading the text value.</returns>
        public virtual TextReader CreateTextReader()
        {
            IJsonStreamReader streamReader = this.innerReader as IJsonStreamReader;

            if (!this.isBuffering && streamReader != null)
            {
                return(streamReader.CreateTextReader());
            }

            TextReader result = new StringReader(this.Value == null ? "" : (string)this.Value);

            this.innerReader.Read();
            return(result);
        }
        /// <summary>
        /// Creates a stream for reading a stream value
        /// </summary>
        /// <returns>A Stream used to read a stream value</returns>
        public virtual Stream CreateReadStream()
        {
            IJsonStreamReader streamReader = this.innerReader as IJsonStreamReader;

            if (!this.isBuffering && streamReader != null)
            {
                return(streamReader.CreateReadStream());
            }

            Stream result = new MemoryStream(this.Value == null ? new byte[0] :
                                             Convert.FromBase64String((string)this.Value));

            this.innerReader.Read();
            return(result);
        }
 private static Task <T> ReadObjectElement <T>(IJsonStreamReader reader,
                                               CancellationToken cancellationToken) =>
 reader.ReadObjectAsync <T>(cancellationToken);
 private static Task <IJsonToken> ReadTokenElement(IJsonStreamReader reader,
                                                   CancellationToken cancellationToken) =>
 reader.ReadTokenAsync(cancellationToken);
 /// <summary>
 /// Read an array at the current point in the stream as an array of POCOs.
 /// </summary>
 /// <typeparam name="T">Type of POCO in the array.</typeparam>
 /// <param name="reader">The <seealso cref="IJsonStreamReader"/>.</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 /// <returns>An <see cref="IAsyncEnumerable{T}"/> of the objects.</returns>
 public static IAsyncEnumerable <T> ReadObjectsAsync <T>(this IJsonStreamReader reader,
                                                         CancellationToken cancellationToken = default) =>
 reader.ReadArrayAsync(ReadObjectElement <T>, cancellationToken);
 /// <summary>
 /// Read an array at the current point in the stream as an array of <seealso cref="IJsonToken"/>.
 /// </summary>
 /// <param name="reader">The <seealso cref="IJsonStreamReader"/>.</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 /// <returns>An <see cref="IAsyncEnumerable{T}"/> of the tokens.</returns>
 public static IAsyncEnumerable <IJsonToken> ReadTokensAsync(this IJsonStreamReader reader,
                                                             CancellationToken cancellationToken = default) =>
 reader.ReadArrayAsync(ReadTokenElement, cancellationToken);