Mantis - Squeak
Viewing Issue Advanced Details
6736 Collections major always 10-19-07 13:28 10-19-07 20:26
noha  
 
normal  
new 3.9  
open  
none    
none  
0006736: PositionableStream>>nextLittleEndianNumber: produces DNU: Character>>bitOr:
nextLittleEndianNumber: reads an amount of characters from a stream and converts them to a number. nextNumber: is working. In netLittleEndianNumber: a call to isInteger is missing.
 PositionableStream-noha-M6736.1.cs [^] (492 bytes) 10-19-07 13:35

Notes
(0011357)
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]
(0011358)
nicolas cellier   
10-19-07 20:26   
In other words, I would prefer #asInteger to be removed from #nextNumber: rather than added to #nextLittleEndianNumber:

A good exception telling me "hey your stream is not binary" is better than a false result...