Skip to content

Commit

Permalink
move fields after constructor and add deprecation to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielaraujoz committed Jul 24, 2023
1 parent 0e7ab54 commit 3499783
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions dio/lib/src/multipart_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ import 'multipart_file/io_multipart_file.dart'
/// MultipartFile is based on stream, and a stream can be read only once,
/// so the same MultipartFile can't be read multiple times.
class MultipartFile {
/// 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].
@Deprecated(
'Clone will not work with this constructor and it will be removed in 6.0.0',
)
MultipartFile(
Stream<List<int>> Function() data,
this.length, {
this.filename,
MediaType? contentType,
Map<String, List<String>>? headers,
}) : _data = data,
headers = caseInsensitiveKeyMap(headers),
contentType = contentType ?? MediaType('application', 'octet-stream'),
_stream = data.call();

/// The size of the file in bytes. This must be known in advance, even if this
/// file is created from a [ByteStream].
final int length;
Expand All @@ -26,7 +46,6 @@ class MultipartFile {
final MediaType? contentType;

/// The stream that will emit the file's contents.
@Deprecated('Use [data] instead.')
final Stream<List<int>> _stream;

// The stream builder that will emit the file's contents for every call.
Expand All @@ -36,23 +55,6 @@ class MultipartFile {
bool get isFinalized => _isFinalized;
bool _isFinalized = false;

/// 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(
Stream<List<int>> Function() data,
this.length, {
this.filename,
MediaType? contentType,
Map<String, List<String>>? headers,
}) : _data = data,
headers = caseInsensitiveKeyMap(headers),
contentType = contentType ?? MediaType('application', 'octet-stream'),
_stream = data.call();

/// Creates a new [MultipartFile] from a byte array.
///
/// [contentType] currently defaults to `application/octet-stream`, but in the
Expand Down

0 comments on commit 3499783

Please sign in to comment.