From ce47230851a3ff525835fe6073e8c32eb4cde4eb Mon Sep 17 00:00:00 2001 From: Johan Brichau Date: Fri, 31 Jul 2020 11:35:24 +0200 Subject: [PATCH] Fix reading contents of empty binary file --- .../instance/contentsOfFile.binary..st | 4 +++- .../instance/testReadWriteEmptyFileInFolderBinary.st | 8 ++++++++ .../instance/testReadWriteEmptyFileInFolderText.st | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testReadWriteEmptyFileInFolderBinary.st create mode 100644 repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testReadWriteEmptyFileInFolderText.st diff --git a/repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/contentsOfFile.binary..st b/repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/contentsOfFile.binary..st index 119ba39b..3c95a9de 100644 --- a/repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/contentsOfFile.binary..st +++ b/repository/Grease-Pharo70-Core.package/GRPharoPlatform.class/instance/contentsOfFile.binary..st @@ -1,3 +1,5 @@ file library contentsOfFile: aString binary: aBoolean - ^ self fileStreamOn: aString do: [ :stream | stream contents ] binary: aBoolean \ No newline at end of file + ^ aBoolean + ifTrue:[ self fileStreamOn: aString do: [ :stream | stream contents ifNil:[ ByteArray new ] ] binary: aBoolean ] + ifFalse:[ self fileStreamOn: aString do: [ :stream | stream contents ] binary: aBoolean ] \ No newline at end of file diff --git a/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testReadWriteEmptyFileInFolderBinary.st b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testReadWriteEmptyFileInFolderBinary.st new file mode 100644 index 00000000..39fbdb1c --- /dev/null +++ b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testReadWriteEmptyFileInFolderBinary.st @@ -0,0 +1,8 @@ +tests-filestreams +testReadWriteEmptyFileInFolderBinary + | bytes | + bytes := ByteArray new. + self + writeToFile: bytes + withFileNameDo:[ :fileName | + self assert: (bytes = (GRPlatform current contentsOfFile: fileName binary: true)) ] \ No newline at end of file diff --git a/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testReadWriteEmptyFileInFolderText.st b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testReadWriteEmptyFileInFolderText.st new file mode 100644 index 00000000..757a5cdb --- /dev/null +++ b/repository/Grease-Tests-Core.package/GRPlatformTest.class/instance/testReadWriteEmptyFileInFolderText.st @@ -0,0 +1,8 @@ +tests-filestreams +testReadWriteEmptyFileInFolderText + | text | + text := String new. + self + writeToFile: text + withFileNameDo:[ :fileName | + self assert: (text = (GRPlatform current contentsOfFile: fileName binary: false)) ] \ No newline at end of file