Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Unified Diff: pkg/http/lib/src/byte_stream.dart

Issue 216603010: Rip out dart:io from pkg/http wherever possible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http/lib/src/base_client.dart ('k') | pkg/http/lib/src/client.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/lib/src/byte_stream.dart
diff --git a/pkg/http/lib/src/byte_stream.dart b/pkg/http/lib/src/byte_stream.dart
index 181d410542d71b75534481157928bd6511d2fc6b..d4e7f70b57e559356d4e022e3fdda2d3ad8400dc 100644
--- a/pkg/http/lib/src/byte_stream.dart
+++ b/pkg/http/lib/src/byte_stream.dart
@@ -6,7 +6,6 @@ library byte_stream;
import 'dart:async';
import 'dart:convert';
-import 'dart:io';
import 'dart:typed_data';
import 'utils.dart';
@@ -14,24 +13,27 @@ import 'utils.dart';
/// A stream of chunks of bytes representing a single piece of data.
class ByteStream extends StreamView<List<int>> {
ByteStream(Stream<List<int>> stream)
- : super(stream);
+ : super(stream);
/// Returns a single-subscription byte stream that will emit the given bytes
/// in a single chunk.
factory ByteStream.fromBytes(List<int> bytes) =>
- new ByteStream(streamFromIterable([bytes]));
+ new ByteStream(streamFromIterable([bytes]));
/// Collects the data of this stream in a [Uint8List].
Future<Uint8List> toBytes() {
- return fold(new BytesBuilder(), (builder, chunk) => builder..add(chunk))
- .then((builder) => builder.takeBytes());
+ var completer = new Completer();
+ var sink = new ByteConversionSink.withCallback(completer.complete);
+ listen(sink.add, onError: completer.completeError, onDone: sink.close,
+ cancelOnError: true);
+ return completer.future;
}
/// Collect the data of this stream in a [String], decoded according to
/// [encoding], which defaults to `UTF8`.
Future<String> bytesToString([Encoding encoding=UTF8]) =>
- toBytes().then((bytes) => encoding.decode(bytes));
+ encoding.decodeStream(this);
Stream<String> toStringStream([Encoding encoding=UTF8]) =>
- transform(encoding.decoder);
+ transform(encoding.decoder);
}
« no previous file with comments | « pkg/http/lib/src/base_client.dart ('k') | pkg/http/lib/src/client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698