Repository navigation
Stream web files in evenly sized chunks and deprecate eager reading options - #2240
Merged
Merged
Conversation
…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
1 of 4 tasks
navaronbracke
approved these changes
Oct 9, 2026
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refs #2223, #2224
The 14.0.0 release (#2236) is on hold until the ecosystem supports
cross_file0.4.0 (see the comment there). This ships the web improvements that do not need it as a minor,file_picker_web4.1.0.Evenly sized chunks
readAsByteStream()on web readblob:URLs through thefetchbody stream, whose chunk sizes are irregular, whilewithReadStreamsliced the file into fixed 1,000,000 byte chunks withFileReader. #2223 showed a real consumer,RamFileData.fromStreamfrom thearchivepackage, that needs evenly sized buffers, so it had to rely onwithReadStream.Both paths now go through a single
streamBlobInChunks, which slices theBlobwithslice()andarrayBuffer()intoWebPlatformFile.streamChunkSize(1 MiB) pieces, so every chunk but the last has the same size. This also replaces theFileReaderbased reader, which looped forever when a read returned no result.With
withReadStreamthe chunk size changes from 1,000,000 bytes to 1 MiB. Chunks stay evenly sized, which is what consumers rely on.Deprecations
withData,withReadStreamandreadSequentialare 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 analyzerinfofor each.Testing
blob:URL, an empty file, and picked files with the default options and withwithReadStream. Against the previous code they fail with irregular chunks (1310720, 786432, 524288) and with 1,000,000 byte chunks respectively.flutter test --platform chromepasses infile_picker_web(26 tests) andflutter analyzeis clean.