示例#1
0
 /// <summary>
 /// Creates a Sink which writes incoming <see cref="ByteString"/>s to an <see cref="Stream"/> created by the given function.
 /// 
 /// Materializes a <see cref="Task{TResult}"/> of <see cref="IOResult"/> that will be completed with the size of the file (in bytes) at the streams completion,
 /// and a possible exception if IO operation was not completed successfully.
 /// 
 /// 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"/>. 
 /// If <paramref name="autoFlush"/> is true the OutputStream will be flushed whenever a byte array is written, defaults to false.
 /// 
 /// The <see cref="Stream"/> will be closed when the stream flowing into this <see cref="Sink{TIn,TMat}"/> is completed. The <see cref="Sink{TIn,TMat}"/>
 /// will cancel the stream when the <see cref="Stream"/> is no longer writable.
 /// </summary>
 /// <param name="createOutputStream">A function which creates the <see cref="Stream"/> to write to</param>
 /// <param name="autoFlush">If set to true the <see cref="Stream"/> will be flushed whenever a byte array is written, default is false</param>
 public static Sink<ByteString, Task<IOResult>> FromOutputStream(Func<Stream> createOutputStream, bool autoFlush = false)
 {
     var shape = new SinkShape<ByteString>(new Inlet<ByteString>("OutputStreamSink"));
     var streamSink = new OutputStreamSink(createOutputStream, DefaultAttributes.OutputStreamSink, shape,
         autoFlush);
     return new Sink<ByteString, Task<IOResult>>(streamSink);
 }
示例#2
0
        /// <summary>
        /// Creates a Sink which writes incoming <see cref="ByteString"/>s to an <see cref="Stream"/> created by the given function.
        ///
        /// Materializes a <see cref="Task{TResult}"/> of <see cref="IOResult"/> that will be completed with the size of the file (in bytes) at the streams completion,
        /// and a possible exception if IO operation was not completed successfully.
        ///
        /// 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"/>.
        /// If <paramref name="autoFlush"/> is true the OutputStream will be flushed whenever a byte array is written, defaults to false.
        ///
        /// The <see cref="Stream"/> will be closed when the stream flowing into this <see cref="Sink{TIn,TMat}"/> is completed. The <see cref="Sink{TIn,TMat}"/>
        /// will cancel the stream when the <see cref="Stream"/> is no longer writable.
        /// </summary>
        /// <param name="createOutputStream">A function which creates the <see cref="Stream"/> to write to</param>
        /// <param name="autoFlush">If set to true the <see cref="Stream"/> will be flushed whenever a byte array is written, default is false</param>
        /// <returns>TBD</returns>
        public static Sink <ByteString, Task <IOResult> > FromOutputStream(Func <Stream> createOutputStream, bool autoFlush = false)
        {
            var shape      = new SinkShape <ByteString>(new Inlet <ByteString>("OutputStreamSink"));
            var streamSink = new OutputStreamSink(createOutputStream, DefaultAttributes.OutputStreamSink, shape,
                                                  autoFlush);

            return(new Sink <ByteString, Task <IOResult> >(streamSink));
        }