finalize method
Freezes all mutable fields and returns a single-subscription ByteStream
that will emit the request body.
Implementation
@override
http.ByteStream finalize() {
final byteStream = super.finalize();
if (onProgress == null) return byteStream;
final total = contentLength;
var bytes = 0;
final t = StreamTransformer.fromHandlers(
handleData: (List<int> data, EventSink<List<int>> sink) {
bytes += data.length;
if (onProgress != null) {
onProgress!(bytes, total);
}
sink.add(data);
},
);
final stream = byteStream.transform(t);
return http.ByteStream(stream);
}