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

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

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 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/io_client.dart ('k') | pkg/http/lib/src/multipart_request.dart » ('j') | 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_file; 5 library multipart_file;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'byte_stream.dart'; 10 import 'byte_stream.dart';
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // TODO(nweiz): Infer the content-type from the filename. 80 // TODO(nweiz): Infer the content-type from the filename.
81 /// Creates a new [MultipartFile] from a [File]. 81 /// Creates a new [MultipartFile] from a [File].
82 /// 82 ///
83 /// [filename] defaults to the name of the file on disk. [contentType] 83 /// [filename] defaults to the name of the file on disk. [contentType]
84 /// currently defaults to `application/octet-stream`, but in the future may be 84 /// currently defaults to `application/octet-stream`, but in the future may be
85 /// inferred from [filename]. 85 /// inferred from [filename].
86 static Future<MultipartFile> fromFile(String field, File file, 86 static Future<MultipartFile> fromFile(String field, File file,
87 {String filename, ContentType contentType}) { 87 {String filename, ContentType contentType}) {
88 if (filename == null) filename = new Path(file.name).filename; 88 if (filename == null) filename = new Path(file.name).filename;
89 return file.length().then((length) { 89 return file.length().then((length) {
90 var stream = wrapInputStream(file.openInputStream()); 90 var stream = new ByteStream(file.openRead());
91 return new MultipartFile(field, stream, length, 91 return new MultipartFile(field, stream, length,
92 filename: filename, 92 filename: filename,
93 contentType: contentType); 93 contentType: contentType);
94 }); 94 });
95 } 95 }
96 96
97 // Finalizes the file in preparation for it being sent as part of a 97 // Finalizes the file in preparation for it being sent as part of a
98 // [MultipartRequest]. This returns a [ByteStream] that should emit the body 98 // [MultipartRequest]. This returns a [ByteStream] that should emit the body
99 // of the file. The stream may be closed to indicate an empty file. 99 // of the file. The stream may be closed to indicate an empty file.
100 ByteStream finalize() { 100 ByteStream finalize() {
101 if (isFinalized) { 101 if (isFinalized) {
102 throw new StateError("Can't finalize a finalized MultipartFile."); 102 throw new StateError("Can't finalize a finalized MultipartFile.");
103 } 103 }
104 _isFinalized = true; 104 _isFinalized = true;
105 return _stream; 105 return _stream;
106 } 106 }
107 } 107 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/io_client.dart ('k') | pkg/http/lib/src/multipart_request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698