X Tutup
Skip to content

Commit ce47230

Browse files
author
Johan Brichau
committed
Fix reading contents of empty binary file
1 parent d321f40 commit ce47230

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
file library
22
contentsOfFile: aString binary: aBoolean
3-
^ self fileStreamOn: aString do: [ :stream | stream contents ] binary: aBoolean
3+
^ aBoolean
4+
ifTrue:[ self fileStreamOn: aString do: [ :stream | stream contents ifNil:[ ByteArray new ] ] binary: aBoolean ]
5+
ifFalse:[ self fileStreamOn: aString do: [ :stream | stream contents ] binary: aBoolean ]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests-filestreams
2+
testReadWriteEmptyFileInFolderBinary
3+
| bytes |
4+
bytes := ByteArray new.
5+
self
6+
writeToFile: bytes
7+
withFileNameDo:[ :fileName |
8+
self assert: (bytes = (GRPlatform current contentsOfFile: fileName binary: true)) ]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests-filestreams
2+
testReadWriteEmptyFileInFolderText
3+
| text |
4+
text := String new.
5+
self
6+
writeToFile: text
7+
withFileNameDo:[ :fileName |
8+
self assert: (text = (GRPlatform current contentsOfFile: fileName binary: false)) ]

0 commit comments

Comments
 (0)
X Tutup