示例#1
0
        /// <summary>
        /// Loads a <see cref="NzbDocument"/> from the specified stream using the specified character encoding.
        /// </summary>
        /// <param name="stream">The stream to be read.</param>
        /// <param name="encoding">The character encoding to use.</param>
        /// <returns>The parsed <see cref="NzbDocument"/>.</returns>
        /// <exception cref="ArgumentNullException">ArgumentNullException</exception>
        public static NzbDocument Load(Stream stream, Encoding encoding)
        {
            Guard.ThrowIfNull(stream, nameof(stream));
            Guard.ThrowIfNull(encoding, nameof(encoding));

            using (var reader = new StreamReader(stream, encoding))
            {
                return(NzbParser.Parse(reader.ReadToEnd()));
            }
        }
示例#2
0
        /// <summary>
        /// Loads a <see cref="NzbDocument"/> from the specified stream asynchronously using the specified character encoding.
        /// </summary>
        /// <param name="stream">The stream to be read.</param>
        /// <param name="encoding">The character encoding to use.</param>
        /// <returns>A task that represents the asynchronous load operation.
        /// The value of the task's result property contains the resulting <see cref="NzbDocument"/>.</returns>
        /// <exception cref="ArgumentNullException">ArgumentNullException</exception>
        public static async Task <NzbDocument> LoadAsync(Stream stream, Encoding encoding)
        {
            Guard.ThrowIfNull(stream, nameof(stream));
            Guard.ThrowIfNull(encoding, nameof(encoding));

            using (var reader = new StreamReader(stream, encoding))
            {
                return(NzbParser.Parse(await reader.ReadToEndAsync()));
            }
        }