Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly type Stream argument as List<int> (#56)
A breaking change (see [0]) will make `utf8.encode()` return the more precise `Uint8List` type (instead of the current `List<int>`). In rare circumstances this can lead to changes in behavior, mainly when code relies on type inference, a different type got inferred and the code dependend on the type not being inferred a more precise type. Here we explicitly use `Stream<List<int>>` instead of relying on type inference (which would infer `Stream<Uint8List>` in some cases after [0]). This is necessary as the stream transformer APIs cannot work with subtypes. Example of code that fails at runtime: ``` import 'dart:typed_data'; import 'dart:convert'; void main() { Stream<Uint8List> stream = Stream.fromIterable([]); Stream<List<int>> stream2 = stream; stream2.transform(utf8.decoder); // ^^^ Will throw due to Utf8Decoder not being subtype of // StreamTransformer<Uint8List, String>. } ``` [0] dart-lang/sdk#52801 Co-authored-by: Natalie Weizenbaum <nweiz@google.com>
- Loading branch information
1 parent
101db6d
commit 36cb86d
Showing
5 changed files
with
13 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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