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

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

Issue 1922883004: Fix more strong-mode warnings. (Closed) Base URL: git@github.com:dart-lang/http@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « lib/http.dart ('k') | pubspec.yaml » ('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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import 'package:async/async.dart';
8 import 'package:http_parser/http_parser.dart'; 9 import 'package:http_parser/http_parser.dart';
9 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
10 11
11 import 'byte_stream.dart'; 12 import 'byte_stream.dart';
12 import 'io.dart' as io; 13 import 'io.dart' as io;
13 import 'utils.dart'; 14 import 'utils.dart';
14 15
15 /// A file to be uploaded as part of a [MultipartRequest]. This doesn't need to 16 /// A file to be uploaded as part of a [MultipartRequest]. This doesn't need to
16 /// correspond to a physical file. 17 /// correspond to a physical file.
17 class MultipartFile { 18 class MultipartFile {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 80
80 // TODO(nweiz): Infer the content-type from the filename. 81 // TODO(nweiz): Infer the content-type from the filename.
81 /// Creates a new [MultipartFile] from a path to a file on disk. 82 /// Creates a new [MultipartFile] from a path to a file on disk.
82 /// 83 ///
83 /// [filename] defaults to the basename of [filePath]. [contentType] currently 84 /// [filename] defaults to the basename of [filePath]. [contentType] currently
84 /// defaults to `application/octet-stream`, but in the future may be inferred 85 /// defaults to `application/octet-stream`, but in the future may be inferred
85 /// from [filename]. 86 /// from [filename].
86 /// 87 ///
87 /// This can only be used in an environment that supports "dart:io". 88 /// This can only be used in an environment that supports "dart:io".
88 static Future<MultipartFile> fromPath(String field, String filePath, 89 static Future<MultipartFile> fromPath(String field, String filePath,
89 {String filename, MediaType contentType}) { 90 {String filename, MediaType contentType}) async {
90 io.assertSupported("MultipartFile.fromPath"); 91 io.assertSupported("MultipartFile.fromPath");
91 if (filename == null) filename = path.basename(filePath); 92 if (filename == null) filename = path.basename(filePath);
92 var file = io.newFile(filePath); 93 var file = io.newFile(filePath);
93 return file.length().then((length) { 94 var length = await file.length();
94 var stream = new ByteStream(file.openRead()); 95 var stream = new ByteStream(DelegatingStream.typed(file.openRead()));
95 return new MultipartFile(field, stream, length, 96 return new MultipartFile(field, stream, length,
96 filename: filename, 97 filename: filename,
97 contentType: contentType); 98 contentType: contentType);
98 });
99 } 99 }
100 100
101 // Finalizes the file in preparation for it being sent as part of a 101 // Finalizes the file in preparation for it being sent as part of a
102 // [MultipartRequest]. This returns a [ByteStream] that should emit the body 102 // [MultipartRequest]. This returns a [ByteStream] that should emit the body
103 // of the file. The stream may be closed to indicate an empty file. 103 // of the file. The stream may be closed to indicate an empty file.
104 ByteStream finalize() { 104 ByteStream finalize() {
105 if (isFinalized) { 105 if (isFinalized) {
106 throw new StateError("Can't finalize a finalized MultipartFile."); 106 throw new StateError("Can't finalize a finalized MultipartFile.");
107 } 107 }
108 _isFinalized = true; 108 _isFinalized = true;
109 return _stream; 109 return _stream;
110 } 110 }
111 } 111 }
OLDNEW
« no previous file with comments | « lib/http.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698