/// <summary> /// Converts a stream paging resolver to a stream collection. /// </summary> /// <param name="streams">A stream paging resolver.</param> /// <returns>A stream collection.</returns> public static IEnumerable <Stream> ToStreamCollection(StreamPagingResolver streams) { if (streams == null) { yield break; } for (var i = 0; ; i++) { Stream stream; try { stream = streams(i); if (stream == null) { break; } } catch (ArgumentException) { break; } yield return(stream); } }
/// <summary> /// Reads characters from the streams and advances the position within each stream to the end. /// </summary> /// <param name="streams">The stream collection to read.</param> /// <param name="encoding">The encoding to read text.</param> /// <param name="closeStream">true if need close stream automatically after read; otherwise, false.</param> /// <returns>Bytes from the stream collection.</returns> /// <exception cref="NotSupportedException">The stream does not support reading.</exception> /// <exception cref="ObjectDisposedException">The stream has disposed.</exception> public static IEnumerable <char> ReadChars(StreamPagingResolver streams, Encoding encoding = null, bool closeStream = false) => ReadChars(StreamCopy.ToStreamCollection(streams), encoding, closeStream);
/// <summary> /// Initializes a new instance of the CharsReader class. /// </summary> /// <param name="streams">The stream collection to read.</param> /// <param name="encoding">The encoding to read text.</param> /// <param name="closeStream">true if need close stream automatically after read; otherwise, false.</param> public CharsReader(StreamPagingResolver streams, Encoding encoding = null, bool closeStream = false) { enumerator = ReadChars(streams, encoding, closeStream).GetEnumerator(); }
/// <summary> /// Reads lines from a specific stream collection. /// </summary> /// <param name="streams">The stream collection to read.</param> /// <param name="encoding">The character encoding to use.</param> /// <param name="removeEmptyLine">true if need remove the empty line; otherwise, false.</param> /// <param name="closeStream">true if need close stream automatically after read; otherwise, false.</param> /// <returns>Lines from the specific stream collection.</returns> /// <exception cref="NotSupportedException">The stream does not support reading.</exception> /// <exception cref="ObjectDisposedException">The stream has disposed.</exception> public static IEnumerable <string> ReadLines(StreamPagingResolver streams, Encoding encoding, bool removeEmptyLine = false, bool closeStream = false) => ReadLines(ReadChars(streams, encoding, closeStream), removeEmptyLine);
/// <summary> /// Reads bytes from the streams and advances the position within each stream to the end. /// </summary> /// <param name="streams">The stream collection to read.</param> /// <param name="closeStream">true if need close stream automatically after read; otherwise, false.</param> /// <returns>Bytes from the stream collection.</returns> /// <exception cref="NotSupportedException">The stream does not support reading.</exception> /// <exception cref="ObjectDisposedException">The stream has disposed.</exception> public static IEnumerable <byte> ReadBytes(StreamPagingResolver streams, bool closeStream = false) { return(ReadBytes(ToStreamCollection(streams), closeStream)); }