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

Side by Side Diff: pkg/http/lib/src/byte_stream.dart

Issue 11825010: Update pkg/http to use the new async APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/lib/src/base_request.dart ('k') | pkg/http/lib/src/io_client.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 library byte_stream;
6
7 import 'dart:async';
8 import 'dart:io';
9 import 'dart:scalarlist';
10
11 import 'utils.dart';
12
13 /// A stream of chunks of bytes representing a single piece of data.
14 class ByteStream extends StreamView<List<int>> {
15 ByteStream(Stream<List<int>> stream)
16 : super(stream);
17
18 /// Returns a single-subscription byte stream that will emit the given bytes
19 /// in a single chunk.
20 factory ByteStream.fromBytes(List<int> bytes) =>
21 new ByteStream(streamFromIterable([bytes]));
22
23 /// Collects the data of this stream in a [Uint8List].
24 Future<Uint8List> toBytes() {
25 /// TODO(nweiz): use BufferList when issue 6409 is fixed.
26 return reduce(<int>[], (buffer, chunk) {
27 buffer.addAll(chunk);
28 return buffer;
29 }).then(toUint8List);
30 }
31
32 /// Collect the data of this stream in a [String], decoded according to
33 /// [encoding], which defaults to `Encoding.UTF_8`.
34 Future<String> bytesToString([Encoding encoding=Encoding.UTF_8]) =>
35 toBytes().then((bytes) => decodeString(bytes, encoding));
36 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/base_request.dart ('k') | pkg/http/lib/src/io_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698