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

Unified Diff: pkg/http/lib/src/multipart_file.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http/lib/src/mock_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 70a0c576e4f113f0b984540e7dfaf2938fb60031..a0b50cb4fa0b2d596161ad715f9d49f3c54df505 100644
--- a/pkg/http/lib/src/multipart_file.dart
+++ b/pkg/http/lib/src/multipart_file.dart
@@ -7,6 +7,7 @@ library multipart_file;
import 'dart:async';
import 'dart:io';
+import 'byte_stream.dart';
import 'utils.dart';
/// A file to be uploaded as part of a [MultipartRequest]. This doesn't need to
@@ -16,7 +17,7 @@ class MultipartFile {
final String field;
/// The size of the file in bytes. This must be known in advance, even if this
- /// file is created from an [InputStream].
+ /// file is created from a [ByteStream].
final int length;
/// The basename of the file. May be null.
@@ -26,21 +27,22 @@ class MultipartFile {
final ContentType contentType;
/// The stream that will emit the file's contents.
- final InputStream _stream;
+ final ByteStream _stream;
/// Whether [finalize] has been called.
bool get isFinalized => _isFinalized;
bool _isFinalized = false;
- /// Creates a new [MultipartFile] from an [InputStream]. The length of the
- /// file in bytes must be known in advance. If it's not, read the data from
- /// the stream and use [MultipartFile.fromBytes] instead.
+ /// Creates a new [MultipartFile] from a chunked [Stream] of bytes. The length
+ /// of the file in bytes must be known in advance. If it's not, read the data
+ /// from the stream and use [MultipartFile.fromBytes] instead.
///
/// [contentType] currently defaults to `application/octet-stream`, but in the
/// future may be inferred from [filename].
- MultipartFile(this.field, this._stream, this.length,
+ MultipartFile(this.field, Stream<List<int>> stream, this.length,
{this.filename, ContentType contentType})
- : this.contentType = contentType != null ? contentType :
+ : this._stream = toByteStream(stream),
+ this.contentType = contentType != null ? contentType :
new ContentType("application", "octet-stream");
/// Creates a new [MultipartFile] from a byte array.
@@ -49,9 +51,7 @@ class MultipartFile {
/// future may be inferred from [filename].
factory MultipartFile.fromBytes(String field, List<int> value,
{String filename, ContentType contentType}) {
- var stream = new ListInputStream();
- stream.write(value);
- stream.markEndOfStream();
+ var stream = new ByteStream.fromBytes(value);
return new MultipartFile(field, stream, value.length,
filename: filename,
contentType: contentType);
@@ -87,16 +87,17 @@ class MultipartFile {
{String filename, ContentType contentType}) {
if (filename == null) filename = new Path(file.name).filename;
return file.length().then((length) {
- return new MultipartFile(field, file.openInputStream(), length,
+ var stream = wrapInputStream(file.openInputStream());
+ return new MultipartFile(field, stream, length,
filename: filename,
contentType: contentType);
});
}
// Finalizes the file in preparation for it being sent as part of a
- // [MultipartRequest]. This returns an [InputStream] that should emit the body
+ // [MultipartRequest]. This returns a [ByteStream] that should emit the body
// of the file. The stream may be closed to indicate an empty file.
- InputStream finalize() {
+ ByteStream finalize() {
if (isFinalized) {
throw new StateError("Can't finalize a finalized MultipartFile.");
}
« no previous file with comments | « pkg/http/lib/src/mock_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