8000 Make MemoryFile.openRead and _ChrootFile.openRead return Stream<List<… · dart-archive/file.dart@f05f5db · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit f05f5db

Browse files
Make MemoryFile.openRead and _ChrootFile.openRead return Stream<List<int>> again (#217)
* Make MemoryFile.openRead and _ChrootFile.openRead return Stream<List<int>> again This is equivalent to #168, but I foolishly neglected to make corresponding changes for all file system types. Fixes https://github.com/google/file.dart/issues/193. * Apply suggestions from natebosch Co-authored-by: Nate Bosch <nbosch1@gmail.com> --------- Co-authored-by: Nate Bosch <nbosch1@gmail.com>
1 parent f2f3076 commit f05f5db

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

packages/file/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Dart 3 fixes for class modifiers.
44
* `MemoryFileSystem` now treats empty paths as non-existent.
55
* Fix `FileSystem.isLink`/`FileSystem.isLinkSync` to not follow symbolic links.
6+
* Make the return type of `MemoryFile.openRead` and `_ChrootFile.openRead` again
7+
match the return type from `dart:io`.
68

79
#### 6.1.4
810

packages/file/lib/src/backends/chroot/chroot_file.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
251251
path, getDelegate(followLinks: true).openSync(mode: mode));
252252

253253
@override
254-
Stream<Uint8List> openRead([int? start, int? end]) =>
255-
getDelegate(followLinks: true).openRead(start, end).cast<Uint8List>();
254+
Stream<List<int>> openRead([int? start, int? end]) =>
255+
getDelegate(followLinks: true).openRead(start, end);
256256

257257
@override
258258
IOSink openWrite({

packages/file/lib/src/backends/memory/memory_file.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class MemoryFile extends MemoryFileSystemEntity implements File {
196196
}
197197

198198
@override
199-
Stream<Uint8List> openRead([int? start, int? end]) {
199+
Stream<List<int>> openRead([int? start, int? end]) {
200200
fileSystem.opHandle(path, FileSystemOp.open);
201201
try {
202202
FileNode node = resolvedBacking as FileNode;
@@ -206,9 +206,9 @@ class MemoryFile extends MemoryFileSystemEntity implements File {
206206
? content.sublist(start)
207207
: content.sublist(start, math.min(end, content.length));
208208
}
209-
return Stream<Uint8List>.fromIterable(<Uint8List>[content]);
209+
return Stream.value(content);
210210
} catch (e) {
211-
return Stream<Uint8List>.fromFuture(Future<Uint8List>.error(e));
211+
return Stream.error(e);
212212
}
213213
}
214214

packages/file/pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ dev_dependencies:
1919
test: ^1.23.1
2020

2121
dependency_overrides:
22-
glob: 2.1.1
22+
# Temporary to break a dependency cycle. See:
23+
# <https://github.com/google/file.dart/pull/217#issuecomment-1530032688>
24+
glob: 2.1.1

packages/file/test/common_tests.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,21 @@ void runCommonTests(
22732273
expect(f, isNot(exists));
22742274
expect(newFile, exists);
22752275
});
2276+
2277+
test('openReadCompatibleWithUtf8Decoder', () async {
2278+
const content = 'Hello world!';
2279+
File file = fs.file(ns('/foo'))
2280+
..createSync()
2281+
..writeAsStringSync(content);
2282+
expect(
2283+
await file
2284+
.openRead()
2285+
.transform(utf8.decoder)
2286+
.transform(const LineSplitter())
2287+
.first,
2288+
content,
2289+
);
2290+
});
22762291
});
22772292

22782293
group('openWrite', () {

0 commit comments

Comments
 (0)
0