/// <summary> /// Creates a <see cref="Source{TOut,TMat}"/> from an <see cref="Stream"/> created by the given function. /// Emitted elements are <paramref name="chunkSize"/> sized <see cref="ByteString"/> elements, /// except the final element, which will be up to <paramref name="chunkSize"/> in size. /// /// You can configure the default dispatcher for this Source by changing the "akka.stream.blocking-io-dispatcher" or /// set it for a given Source by using <see cref="ActorAttributes.CreateDispatcher"/>. /// /// It materializes a <see cref="Task{TResult}"/> of <see cref="IOResult"/> containing the number of bytes read from the source file upon completion, /// and a possible exception if IO operation was not completed successfully. /// /// The created <see cref="Stream"/> will be closed when the <see cref="Source{TOut,TMat}"/> is cancelled. /// </summary> /// <param name="createInputStream">A function which creates the <see cref="Stream"/> to read from</param> /// <param name="chunkSize">The size of each read operation, defaults to 8192</param> public static Source<ByteString, Task<IOResult>> FromInputStream(Func<Stream> createInputStream, int chunkSize = 8192) { var shape = new SourceShape<ByteString>(new Outlet<ByteString>("InputStreamSource")); var streamSource = new InputStreamSource(createInputStream, chunkSize, DefaultAttributes.InputStreamSource, shape); return new Source<ByteString, Task<IOResult>>(streamSource); }