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

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

Issue 11411241: Use Futures.forEach in http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library multipart_request; 5 library multipart_request;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:math'; 8 import 'dart:math';
9 import 'dart:uri'; 9 import 'dart:uri';
10 import 'dart:utf'; 10 import 'dart:utf';
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 void writeUtf8(String string) => stream.write(encodeUtf8(string)); 95 void writeUtf8(String string) => stream.write(encodeUtf8(string));
96 void writeLine() => stream.write([13, 10]); // \r\n 96 void writeLine() => stream.write([13, 10]); // \r\n
97 97
98 fields.forEach((name, value) { 98 fields.forEach((name, value) {
99 writeAscii('--$boundary\r\n'); 99 writeAscii('--$boundary\r\n');
100 writeAscii(_headerForField(name, value)); 100 writeAscii(_headerForField(name, value));
101 writeUtf8(value); 101 writeUtf8(value);
102 writeLine(); 102 writeLine();
103 }); 103 });
104 104
105 forEachFuture(files, (file) { 105 Futures.forEach(files, (file) {
106 writeAscii('--$boundary\r\n'); 106 writeAscii('--$boundary\r\n');
107 writeAscii(_headerForFile(file)); 107 writeAscii(_headerForFile(file));
108 return writeInputToInput(file.finalize(), stream) 108 return writeInputToInput(file.finalize(), stream)
109 .transform((_) => writeLine()); 109 .transform((_) => writeLine());
110 }).then((_) { 110 }).then((_) {
111 // TODO(nweiz): pass any errors propagated through this future on to 111 // TODO(nweiz): pass any errors propagated through this future on to
112 // the stream. See issue 3657. 112 // the stream. See issue 3657.
113 writeAscii('--$boundary--\r\n'); 113 writeAscii('--$boundary--\r\n');
114 stream.markEndOfStream(); 114 stream.markEndOfStream();
115 }); 115 });
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 String _boundaryString(int length) { 157 String _boundaryString(int length) {
158 var prefix = "dart-http-boundary-"; 158 var prefix = "dart-http-boundary-";
159 var list = new List<int>(length - prefix.length); 159 var list = new List<int>(length - prefix.length);
160 for (var i = 0; i < list.length; i++) { 160 for (var i = 0; i < list.length; i++) {
161 list[i] = _BOUNDARY_CHARACTERS[ 161 list[i] = _BOUNDARY_CHARACTERS[
162 _random.nextInt(_BOUNDARY_CHARACTERS.length)]; 162 _random.nextInt(_BOUNDARY_CHARACTERS.length)];
163 } 163 }
164 return "$prefix${new String.fromCharCodes(list)}"; 164 return "$prefix${new String.fromCharCodes(list)}";
165 } 165 }
166 } 166 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698