Skip to content

Commit 506d251

Browse files
authored
Clean up some unused or underused utilities (#316)
- Remove methods that have no calls. - Replace a call to `writeStreamToSink` with the built in `addStream`. - Replace a legacy style predicate matcher with a `TypeMatcher.having`.
1 parent 9fc6247 commit 506d251

File tree

3 files changed

+4
-79
lines changed

3 files changed

+4
-79
lines changed

lib/src/multipart_request.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@ class MultipartRequest extends BaseRequest {
109109
writeLine();
110110
});
111111

112-
Future.forEach(_files, (file) {
112+
Future.forEach(_files, (MultipartFile file) {
113113
writeAscii('--$boundary\r\n');
114114
writeAscii(_headerForFile(file));
115-
return writeStreamToSink(file.finalize(), controller)
116-
.then((_) => writeLine());
115+
return controller.addStream(file.finalize()).then((_) => writeLine());
117116
}).then((_) {
118117
// TODO(nweiz): pass any errors propagated through this future on to
119118
// the stream. See issue 3657.

lib/src/utils.dart

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,6 @@ String mapToQuery(Map<String, String> map, {Encoding encoding}) {
2121
return pairs.map((pair) => '${pair[0]}=${pair[1]}').join('&');
2222
}
2323

24-
/// Like [String.split], but only splits on the first occurrence of the pattern.
25-
///
26-
/// This will always return an array of two elements or fewer.
27-
///
28-
/// split1("foo,bar,baz", ","); //=> ["foo", "bar,baz"]
29-
/// split1("foo", ","); //=> ["foo"]
30-
/// split1("", ","); //=> []
31-
List<String> split1(String toSplit, String pattern) {
32-
if (toSplit.isEmpty) return <String>[];
33-
34-
var index = toSplit.indexOf(pattern);
35-
if (index == -1) return [toSplit];
36-
return [
37-
toSplit.substring(0, index),
38-
toSplit.substring(index + pattern.length)
39-
];
40-
}
41-
4224
/// Returns the [Encoding] that corresponds to [charset].
4325
///
4426
/// Returns [fallback] if [charset] is null or if no [Encoding] was found that
@@ -92,51 +74,3 @@ Stream<T> onDone<T>(Stream<T> stream, void onDone()) =>
9274
sink.close();
9375
onDone();
9476
}));
95-
96-
// TODO(nweiz): remove this when issue 7786 is fixed.
97-
/// Pipes all data and errors from [stream] into [sink]. When [stream] is done,
98-
/// [sink] is closed and the returned [Future] is completed.
99-
Future store(Stream stream, EventSink sink) {
100-
var completer = Completer();
101-
stream.listen(sink.add, onError: sink.addError, onDone: () {
102-
sink.close();
103-
completer.complete();
104-
});
105-
return completer.future;
106-
}
107-
108-
/// Pipes all data and errors from [stream] into [sink]. Completes [Future] once
109-
/// [stream] is done. Unlike [store], [sink] remains open after [stream] is
110-
/// done.
111-
Future writeStreamToSink(Stream stream, EventSink sink) {
112-
var completer = Completer();
113-
stream.listen(sink.add,
114-
onError: sink.addError, onDone: () => completer.complete());
115-
return completer.future;
116-
}
117-
118-
/// A pair of values.
119-
class Pair<E, F> {
120-
E first;
121-
F last;
122-
123-
Pair(this.first, this.last);
124-
125-
@override
126-
String toString() => '($first, $last)';
127-
128-
@override
129-
bool operator ==(other) {
130-
if (other is! Pair) return false;
131-
return other.first == first && other.last == last;
132-
}
133-
134-
@override
135-
int get hashCode => first.hashCode ^ last.hashCode;
136-
}
137-
138-
/// Configures [future] so that its result (success or exception) is passed on
139-
/// to [completer].
140-
void chainToCompleter(Future future, Completer completer) {
141-
future.then(completer.complete, onError: completer.completeError);
142-
}

test/utils.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,9 @@ class _BodyMatches extends Matcher {
106106
}
107107
}
108108

109-
/// A matcher that matches a [http.ClientException] with the given [message].
110-
///
111-
/// [message] can be a String or a [Matcher].
112-
Matcher isClientException(message) => predicate((error) {
113-
expect(error, TypeMatcher<http.ClientException>());
114-
expect(error.message, message);
115-
return true;
116-
});
117-
118109
/// A matcher that matches function or future that throws a
119110
/// [http.ClientException] with the given [message].
120111
///
121112
/// [message] can be a String or a [Matcher].
122-
Matcher throwsClientException(message) => throwsA(isClientException(message));
113+
Matcher throwsClientException(message) => throwsA(
114+
isA<http.ClientException>().having((e) => e.message, 'message', message));

0 commit comments

Comments
 (0)