Repository navigation
feat(storage)!: report upload progress and download byte ranges #1981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
spydon
merged 4 commits into
main
from
lukasklingsbo/sdk-2277-featstorage-upload-progress-callback-and-byte-range
Oct 19, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fca8309
feat(storage): report upload progress and download byte ranges
spydon 5309325
fix(storage)!: harden upload progress and ranged downloads
spydon e399206
fix(common): create request body slices as they are consumed
spydon 37b8757
Merge branch 'main' into lukasklingsbo/sdk-2277-featstorage-upload-pr…
spydon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import 'dart:math'; | ||
| import 'dart:typed_data'; | ||
|
|
||
| const _sliceLength = 64 * 1024; | ||
|
|
||
| /// Passes [body] through with every chunk larger than 64 KiB split into | ||
| /// slices of at most that size, so a body held in memory as a single chunk | ||
| /// is also handed to the HTTP client a bit at a time. | ||
| Stream<List<int>> sliceRequestBody(Stream<List<int>> body) => | ||
| body.asyncExpand(_slices); | ||
|
|
||
| Stream<List<int>> _slices(List<int> chunk) { | ||
| if (chunk.length <= _sliceLength) return Stream.value(chunk); | ||
| return Stream.fromIterable([ | ||
| for (var start = 0; start < chunk.length; start += _sliceLength) | ||
| if (chunk is Uint8List) | ||
| Uint8List.sublistView( | ||
| chunk, | ||
| start, | ||
| min(start + _sliceLength, chunk.length), | ||
| ) | ||
| else | ||
| chunk.sublist(start, min(start + _sliceLength, chunk.length)), | ||
| ]); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import 'dart:typed_data'; | ||
|
|
||
| import 'package:supabase_common/supabase_common.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| group('sliceRequestBody', () { | ||
| test('splits a large chunk into views of at most 64 KiB', () async { | ||
| final chunk = Uint8List(150 * 1024); | ||
|
|
||
| final slices = await sliceRequestBody(Stream.value(chunk)).toList(); | ||
|
|
||
| expect(slices.map((slice) => slice.length), [ | ||
| 64 * 1024, | ||
| 64 * 1024, | ||
| 22 * 1024, | ||
| ]); | ||
| expect(slices.first, isA<Uint8List>()); | ||
| expect((slices.first as Uint8List).buffer, chunk.buffer); | ||
| }); | ||
|
|
||
| test('passes a small chunk through unchanged', () async { | ||
| final chunk = [1, 2, 3]; | ||
|
|
||
| final slices = await sliceRequestBody(Stream.value(chunk)).toList(); | ||
|
|
||
| expect(slices.single, same(chunk)); | ||
| }); | ||
|
|
||
| test('splits a chunk that is not a Uint8List', () async { | ||
| final chunk = List.filled(64 * 1024 + 1, 0); | ||
|
|
||
| final slices = await sliceRequestBody(Stream.value(chunk)).toList(); | ||
|
|
||
| expect(slices.map((slice) => slice.length), [64 * 1024, 1]); | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.