Skip to content

Stream web files in evenly sized chunks and deprecate eager reading options - #2240

Merged
vicajilau merged 3 commits into
mainfrom
feat/web-even-stream-chunks
Oct 9, 2026
Merged

vicajilau merged 3 commits into
mainfrom
feat/web-even-stream-chunks

Conversation

@vicajilau

Copy link
Copy Markdown
Owner

Refs #2223, #2224

The 14.0.0 release (#2236) is on hold until the ecosystem supports cross_file 0.4.0 (see the comment there). This ships the web improvements that do not need it as a minor, file_picker_web 4.1.0.

Evenly sized chunks

readAsByteStream() on web read blob: URLs through the fetch body stream, whose chunk sizes are irregular, while withReadStream sliced the file into fixed 1,000,000 byte chunks with FileReader. #2223 showed a real consumer, RamFileData.fromStream from the archive package, that needs evenly sized buffers, so it had to rely on withReadStream.

Both paths now go through a single streamBlobInChunks, which slices the Blob with slice() and arrayBuffer() into WebPlatformFile.streamChunkSize (1 MiB) pieces, so every chunk but the last has the same size. This also replaces the FileReader based reader, which looped forever when a read returned no result.

With withReadStream the chunk size changes from 1,000,000 bytes to 1 MiB. Chunks stay evenly sized, which is what consumers rely on.

Deprecations

withData, withReadStream and readSequential are deprecated ahead of their removal in 14.0.0. The annotation is on both the fields and the constructor parameters, since deprecating only the fields does not warn when the options are passed to the constructor, which is how apps use them. I checked that an app using them now gets an analyzer info for each.

Testing

  • New tests for evenly sized chunks over a blob: URL, an empty file, and picked files with the default options and with withReadStream. Against the previous code they fail with irregular chunks (1310720, 786432, 524288) and with 1,000,000 byte chunks respectively.
  • flutter test --platform chrome passes in file_picker_web (26 tests) and flutter analyze is clean.

…ptions

readAsByteStream() read blob: URLs through the fetch body stream, whose chunk sizes are irregular, while withReadStream sliced the file into fixed 1,000,000 byte chunks with FileReader. Consumers such as RamFileData.fromStream from the archive package need evenly sized buffers, so they had to rely on withReadStream.

Both paths now slice the Blob with slice() and arrayBuffer() into WebPlatformFile.streamChunkSize (1 MiB) pieces, so every chunk but the last has the same size. This also replaces the FileReader based reader, which looped forever when a read returned no result.

withData, withReadStream and readSequential are deprecated, on both the fields and the constructor parameters, ahead of their removal in 14.0.0.

Bumps file_picker_web to 4.1.0.

Refs #2223

@navaronbracke navaronbracke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM with nits

Comment thread packages/file_picker_web/CHANGELOG.md Outdated
Comment thread packages/file_picker_web/test/file_picker_web_pick_test.dart Outdated
Comment thread packages/file_picker_web/test/file_picker_web_pick_test.dart Outdated
Comment thread packages/file_picker_web/lib/src/file_picker_web_options.dart Outdated
vicajilau and others added 2 commits October 9, 2026 07:33
Co-authored-by: Navaron Bracke <brackenavaron@gmail.com>
Name the package in the deprecation messages, since 14.0.0 is the file_picker version and not the file_picker_web one. Split the chunking test into one test per option so the deprecated case can be deleted on its own in 14.0.0, and rename the pick helper to pickFiles.
@vicajilau
vicajilau merged commit 9f53465 into main Oct 9, 2026
17 checks passed
@vicajilau
vicajilau deleted the feat/web-even-stream-chunks branch October 9, 2026 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants