Line data Source code
1 : // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 2 : // for details. All rights reserved. Use of this source code is governed by a 3 : // BSD-style license that can be found in the LICENSE file. 4 : 5 : import 'dart:async'; 6 : 7 : /// Simple delegating wrapper around a [StreamSink]. 8 : /// 9 : /// Subclasses can override individual methods, or use this to expose only the 10 : /// [StreamSink] methods of a subclass. 11 : class DelegatingStreamSink<T> implements StreamSink<T> { 12 : final StreamSink _sink; 13 : 14 0 : @override 15 0 : Future get done => _sink.done; 16 : 17 : /// Create delegating sink forwarding calls to [sink]. 18 0 : DelegatingStreamSink(StreamSink<T> sink) : _sink = sink; 19 : 20 0 : DelegatingStreamSink._(this._sink); 21 : 22 : /// Creates a wrapper that coerces the type of [sink]. 23 : /// 24 : /// Unlike [new StreamSink], this only requires its argument to be an instance 25 : /// of `StreamSink`, not `StreamSink<T>`. This means that calls to [add] may 26 : /// throw a [TypeError] if the argument type doesn't match the reified type of 27 : /// [sink]. 28 0 : @Deprecated( 29 : 'Use StreamController<T>(sync: true)..stream.cast<S>().pipe(sink)') 30 : static StreamSink<T> typed<T>(StreamSink sink) => 31 0 : sink is StreamSink<T> ? sink : DelegatingStreamSink._(sink); 32 : 33 0 : @override 34 : void add(T data) { 35 0 : _sink.add(data); 36 : } 37 : 38 0 : @override 39 : void addError(error, [StackTrace? stackTrace]) { 40 0 : _sink.addError(error, stackTrace); 41 : } 42 : 43 0 : @override 44 0 : Future addStream(Stream<T> stream) => _sink.addStream(stream); 45 : 46 0 : @override 47 0 : Future close() => _sink.close(); 48 : }