Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions app/lib/package/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1825,21 +1825,20 @@ Future _saveTarballToFS(Stream<List<int>> data, String filename) async {
await targetFile.delete();
}
try {
final sink = targetFile.openWrite();
int receivedBytes = 0;
final stream = data.transform<List<int>>(
StreamTransformer<List<int>, List<int>>.fromHandlers(
handleData: (chunk, sink) {
receivedBytes += chunk.length;
if (receivedBytes <= UploadSignerService.maxUploadSize) {
sink.add(chunk);
} else {
sink.addError(PackageRejectedException.archiveTooLarge(
UploadSignerService.maxUploadSize));
}
},
),
);
await stream.pipe(targetFile.openWrite());
await for (final chunk in data) {
receivedBytes += chunk.length;
if (receivedBytes <= UploadSignerService.maxUploadSize) {
sink.add(chunk);
} else {
await sink.close();
throw PackageRejectedException.archiveTooLarge(
UploadSignerService.maxUploadSize);
}
}
await sink.flush();
await sink.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the close be in a finally block?

} catch (e, st) {
_logger.warning('An error occurred while streaming tarball to FS.', e, st);
rethrow;
Expand Down