[analyzer] Fix _OverlayFile.writeAsBytesSync

Change-Id: I3b4d7ad2b7a781c49abebef307a44dd9b3381b37
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510361
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
This commit is contained in:
Jens Johansen
2026-06-10 01:08:18 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent fa2e23b83c
commit abd32d5449
2 changed files with 13 additions and 1 deletions
@@ -205,7 +205,10 @@ class _OverlayFile extends _OverlayResource implements File {
@override
void writeAsBytesSync(List<int> bytes) {
writeAsStringSync(String.fromCharCodes(bytes));
if (provider.hasOverlay(path)) {
throw FileSystemException(path, 'Cannot write a file with an overlay');
}
_file.writeAsBytesSync(bytes);
}
@override
@@ -354,6 +354,15 @@ class FileTest extends OverlayTestSupport {
expect(file.toUri(), Uri.file(file.path));
}
test_write_read_bytes_can_be_read_as_string() {
var expectedContent = "æble";
File file = _file(exists: true, content: expectedContent);
expect(file.readAsStringSync(), expectedContent);
var byteContent = file.readAsBytesSync();
file.writeAsBytesSync(byteContent);
expect(file.readAsStringSync(), expectedContent);
}
test_writeAsBytesSync_withoutOverlay() {
File file = _file(exists: true);
var bytes = Uint8List.fromList([99, 99]);