예제 #1
0
/*
Copy a producer stream to a consumer stream.

Returns an optional error and, if error is not nil, a flag indicating whether this error had happened in the consumer (false) or the producer (true).
*/
func Copy(drain stream.Stream, sink Stream) (error, bool) {
	for {
		val, err := drain.Next()
		if err == stream.EOI {
			break
		}
		if err != nil {
			return err, false
		}

		if err := sink.Add(val); err != nil {
			return err, true
		}
	}
	return nil, false
}
예제 #2
0
// An analog of Copy for BufferedStream sink.
func CopyDirect(drain stream.Stream, sink *BufferedStream) (error, bool) {
	for {
		val, err := drain.Next()
		if err == stream.EOI {
			break
		}
		if err != nil {
			return err, false
		}

		if err := sink.addDirect(val); err != nil {
			return err, true
		}
	}
	return nil, false
}