2 ms·
In Smalltalk, it's just a normal function you can add to Filename: doWithStreamThenClose: aBlock | fileStream | fileStream := self newRead
by stcredzero 16y ago
In Smalltalk, it's just a normal function you can add to Filename:
doWithStreamThenClose: aBlock
| fileStream |
fileStream := self newReadWriteStream.
^[aBlock value: fileStream]
ensure: [fileStream close]
This allows one to do:
(Filename named: 'mypath/foo.dat')
doWithStreamThenClose: [ :fileStream |
"do whatever you want with fileStream"
"it shall be closed"
].