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

Unified Diff: pkg/http/lib/src/multipart_file.dart

Issue 216603010: Rip out dart:io from pkg/http wherever possible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/lib/src/multipart_file.dart
diff --git a/pkg/http/lib/src/multipart_file.dart b/pkg/http/lib/src/multipart_file.dart
index d316e2acf4792f131c6c92be414bb68f654f3ae2..220c28633f4cb59b7e63817e3a7fd6d6c614096a 100644
--- a/pkg/http/lib/src/multipart_file.dart
+++ b/pkg/http/lib/src/multipart_file.dart
@@ -5,9 +5,10 @@
library multipart_file;
import 'dart:async';
-import 'dart:convert';
import 'dart:io';
+import 'dart:convert';
+import 'package:http_parser/http_parser.dart';
import 'package:path/path.dart' as path;
import 'package:stack_trace/stack_trace.dart';
@@ -28,7 +29,7 @@ class MultipartFile {
final String filename;
/// The content-type of the file. Defaults to `application/octet-stream`.
- final ContentType contentType;
+ final MediaType contentType;
/// The stream that will emit the file's contents.
final ByteStream _stream;
@@ -44,17 +45,17 @@ class MultipartFile {
/// [contentType] currently defaults to `application/octet-stream`, but in the
/// future may be inferred from [filename].
MultipartFile(this.field, Stream<List<int>> stream, this.length,
- {this.filename, ContentType contentType})
+ {this.filename, MediaType contentType})
: this._stream = toByteStream(stream),
this.contentType = contentType != null ? contentType :
- new ContentType("application", "octet-stream");
+ new MediaType("application", "octet-stream");
/// Creates a new [MultipartFile] from a byte array.
///
/// [contentType] currently defaults to `application/octet-stream`, but in the
/// future may be inferred from [filename].
factory MultipartFile.fromBytes(String field, List<int> value,
- {String filename, ContentType contentType}) {
+ {String filename, MediaType contentType}) {
var stream = new ByteStream.fromBytes(value);
return new MultipartFile(field, stream, value.length,
filename: filename,
@@ -68,16 +69,11 @@ class MultipartFile {
/// [contentType] currently defaults to `text/plain; charset=utf-8`, but in
/// the future may be inferred from [filename].
factory MultipartFile.fromString(String field, String value,
- {String filename, ContentType contentType}) {
- contentType = contentType == null ? new ContentType("text", "plain")
+ {String filename, MediaType contentType}) {
+ contentType = contentType == null ? new MediaType("text", "plain")
: contentType;
- var charset = contentType.charset;
- var encoding = encodingForCharset(contentType.charset, UTF8);
- // Make a new contentType with ensured charset.
- contentType = new ContentType(contentType.primaryType,
- contentType.subType,
- charset: encoding.name,
- parameters: contentType.parameters);
+ var encoding = encodingForCharset(contentType.parameters['charset'], UTF8);
+ contentType = contentType.change(parameters: {'charset': encoding.name});
return new MultipartFile.fromBytes(field, encoding.encode(value),
filename: filename,
@@ -91,7 +87,7 @@ class MultipartFile {
/// defaults to `application/octet-stream`, but in the future may be inferred
/// from [filename].
static Future<MultipartFile> fromPath(String field, String filePath,
- {String filename, ContentType contentType}) {
+ {String filename, MediaType contentType}) {
if (filename == null) filename = path.basename(filePath);
var file = new File(filePath);
return Chain.track(file.length()).then((length) {
« 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