(0011357 - 1164 - 1398 - 1398 - 1398 - 1398 - 1398)
nicolas cellier
10-19-07 20:14
|
Yes, good catch.
However, this might be a false good idea, because some file stream can groke several bytes with a single #next message (for example transform a CR-LF pair into a single Character cr).
The only safe way is to send #binary to your stream.
Observe typical example of #nextNumber: failure below:
| f n1 n2 |
f := FileStream newFileNamed: 'foo'.
[f binary.
f nextPutAll: #(16r01 16r02 16r0D 16r0A 16r00) asByteArray] ensure: [f close].
f := FileStream oldFileNamed: 'foo'.
n1 := [f binary.
f nextNumber: 4] ensure: [f close].
f := FileStream oldFileNamed: 'foo'.
n2 := [f ascii; wantsLineEndConversion: true.
f nextNumber: 4] ensure: [f close].
^({n1. n2.}) collect: [:e | e printStringBase: 16]
Another case with UTF-8:
| f n1 n2 |
f := FileStream newFileNamed: 'foo'.
[f binary.
f nextPutAll: #(16r01 16r02 16rE0 16r04 16r05 16r06) asByteArray] ensure: [f close].
f := FileStream oldFileNamed: 'foo'.
n1 := [f binary.
f nextNumber: 4] ensure: [f close].
f := FileStream oldFileNamed: 'foo'.
n2 := [f ascii.
f nextNumber: 4] ensure: [f close].
^ ({n1. n2.}) collect: [:e | e printStringBase: 16] |