X Tutup
Skip to content

Commit 0168127

Browse files
author
Johan Brichau
authored
Merge pull request SeasideSt#108 from SeasideSt/107-Pharo7-contents-of-empty-binary-file-are-nil-rather-than-an-empty-instance-of-ByteArray
Fix reading contents of empty binary file
2 parents 625f0ba + ce47230 commit 0168127

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