Index: sdk/lib/_internal/js_runtime/lib/core_patch.dart |
diff --git a/sdk/lib/_internal/js_runtime/lib/core_patch.dart b/sdk/lib/_internal/js_runtime/lib/core_patch.dart |
index 971b37f96e36270c2b6726a7f0ba5f2b83033563..799721c9f6b3c310b55174bb9b08ace2c0fde80e 100644 |
--- a/sdk/lib/_internal/js_runtime/lib/core_patch.dart |
+++ b/sdk/lib/_internal/js_runtime/lib/core_patch.dart |
@@ -17,7 +17,8 @@ import 'dart:_js_helper' show patch, |
ConstantMap, |
stringJoinUnchecked, |
objectHashCode, |
- Closure; |
+ Closure, |
+ readHttp; |
import 'dart:_native_typed_data' show NativeUint8List; |
@@ -576,14 +577,35 @@ class _Resource implements Resource { |
} |
Stream<List<int>> _readAsStream(Uri uri) { |
- throw new UnimplementedError("Streaming bytes via HTTP"); |
+ var controller = new StreamController(); |
Siggi Cherem (dart-lang)
2015/08/22 02:21:16
couple comments:
- do we need to add an import to
Harry Terkelsen
2015/08/25 00:03:57
No, dart:core imports dart:async now
|
+ // We only need to implement the listener as there is no way to provide |
+ // back pressure into the channel. |
+ controller.onListen = () { |
+ // Once there is a listener, we kick off the loading of the resource. |
+ readAsBytes().then((value) { |
+ // The resource loading implementation sends all of the data in a |
+ // single message. So the stream will only get a single value posted. |
Siggi Cherem (dart-lang)
2015/08/22 02:21:15
seems like a good simplification for us. I guess w
Harry Terkelsen
2015/08/25 00:03:57
Done.
|
+ controller.add(value); |
+ controller.close(); |
+ }, |
+ onError: (e, s) { |
+ // In case the future terminates with an error we propagate it to the |
+ // stream. |
+ controller.addError(e, s); |
+ controller.close(); |
+ }); |
+ }; |
+ |
+ return controller.stream; |
} |
Future<List<int>> _readAsBytes(Uri uri) { |
Siggi Cherem (dart-lang)
2015/08/22 02:21:15
consider using `=>`:
Future<List<int>> _readAs
Harry Terkelsen
2015/08/25 00:03:57
Done.
|
- throw new UnimplementedError("Reading bytes via HTTP"); |
+ return _readAsString(uri).then((data) { |
+ return data.codeUnits; |
Siggi Cherem (dart-lang)
2015/08/22 02:21:15
do we need to also handle results when the xhr.res
Harry Terkelsen
2015/08/25 00:03:57
On 2015/08/22 02:21:15, Siggi Cherem (dart-lang) w
|
+ }); |
} |
Future<String> _readAsString(Uri uri) { |
Siggi Cherem (dart-lang)
2015/08/22 02:21:16
nit: use '=>' here too
Harry Terkelsen
2015/08/25 00:03:57
Done.
|
- throw new UnimplementedError("Reading string via HTTP"); |
+ return readHttp(uri.toString()); |
Siggi Cherem (dart-lang)
2015/08/22 02:21:16
nit: consider using '$uri' instead of uri.toString
Harry Terkelsen
2015/08/25 00:03:57
Done.
|
} |
} |